I have been able to add syntax highlighting to my .liquid files by following the instructions here: Enabling Liquid templating syntax highlight in webStorm/phpStorm
It worked fine for my HTML and liquid syntax highlighting as it's so similar to Twig.
But my issue is I also have my schema included in each of my .liquid templates. The schema is JSON but there's not syntax highlighting on it at all.
Is there a way to add a custom syntax highlighting for a file type if it's wrapped in some sort of delimiter?
My schema is wrapped like so:
{% schema %}
JSON object with my settings/configuration
{% endschema %}
See image below:
As #yole have said: you cannot do that. Well... permanently.
You can always inject JSON there manually .. and it will last for a while (a session for sure).
Just place caret just after {% schema %} and hit Alt + Enter.
Choose Inject language or reference and locate JSON in the list (speed search works there as well, so just start typing).
Result is obvious:
You are using Twig plugin for .liquid files (native support for them (RUBY-7210) does not seem to be on JetBrains short list right now).
It's now possible to have permanent Language Injection in custom Twig tag (using Twig plugin). See the screenshot below for custom injection rule that you can create yourself:
You can inject JSON in your {% schema %} block manually via Alt+Enter, Inject language or reference > JSON:
See also https://blog.jetbrains.com/phpstorm/2017/12/twig-handling-improvements/
At my org we use a custom .amg filetype for an internal framework that is essentially just a JSON
I made IntelliJ treat those as JSONs by adding *.amg pattern under Recognized File Types > JSON
reference: JetBrains / File type associations
Related
I have just started with Pelican. It's awesome, I just can't figure out how to use macros in my articles (and pages). I know I can use Jinja when making my own theme, but I can't seem to be able to use it in articles. I'd like to be able to define a macro/function/template/whatever that I'd put directly in the markdown of the article, possibly with parameters, and it would get expanded when the pages are generated. For example a function to generate an image with a caption of given size and css class that would also be a link directly to the image. I'd like to be able to access these macros from all articles, to be able to reuse them everywhere. Something I'd normally do with PhP.
I could probably use JS to do this, but if I'd like to avoid it and keep everything static if possible. Can this be done?
UPDATE:
I found a pelican plugin that solves this - jinja2content.
OLD SOLUTION:
I found a solution here. You can implement a filter in Python to process all texts in articles/pages like this:
Create a python file filters.py in which you write the filter function process_text to expand my macros (or generally do anything with the article/page text), for example to test the function write something like:
def process_text(input_text):
return "TEST " + input_text
In the Pelican config file (pelicanconfig.py) register this function as a possible filter to be used with Jinja:
import sys
sys.path.append('.')
import filters
JINJA_FILTERS = {'process_text':filters.process_text}
Now you have to edit the templates to apply this filter to article/page texts before adding them to output. In my case I edited two files: themes/themename/templates/article.html and themes/themename/templates/post.html and changed {{ article.content }} to {{ article.content|process_text }} and {{ page.content }} to {{ page.content|process_text }} in them to apply the filter.
Now all texts in articles and pages should be prefixed with "TEST".
The not so convenient thing about this is I have to write my own macro expander, which shouldn't be extremely hard with regular expression in Python, but if there is a nicer way to do this, feel free to post here.
I have a newbie question. I've been recently trying out Django, and I notice that if I ever write a template tag of the sort:
{% if some_var < 10 %}
the < symbol is highlighted in sublime almost as if it's a syntax error (or warning). Now of course it works correctly, but I'm wondering why this highlighting occurs in the first place. Do some browsers have difficulty parsing < when reading HTML code or something? Please enlighten me (and > doesn't get highlighted to make matters worse!).
I'm actually considering writing a custom template tag that performs the "is less than" comparison.
Sublime probably thinks your template is a plain HTML file, in which case < and > are elements of HTML tags and don't make sense anywhere else.
You might be able to manually set the filetype to be a Django template which should fix the highlighting.
Check out the Djaneiro package. It contains an HTML (Django) syntax definition that contains scopes for template tags:
(The color scheme is my Neon Color Scheme, which contains colors specifically for Djaneiro)
Another option is to upgrade to Sublime Text 3, which is highly recommended anyway. The default HTML syntax definition (along with many other languages, including JavaScript, PHP, and Python) has been completely rewritten, and template tags are now ignored:
Hi sorry that I may not be able to give out more information, but can I ask what the error message (dir1/dir2/dir3/error.md: Template syntax error: Invalid block tag: 'endif') may indicate?
So basically I have a HTML and a Markdown file that seem to be linked somehow in an environment, I'm thinking there must be another Django templates existing somewhere that store the variables and values shown in both the HTML and Markdown files. The HTML and markdown files have variables inside like {%I'mavariable%}.
I wanted to provide more information, but I don't know much more than this to be honest. But I was told that the corresponding html actually break the build...
So what are some potential possibilities/errors that made the build fail? The endif tag may refer to the variable {% dynamics endif %} in the html I guess?
Thank you so much!
I stumbled upon this code:
<a href="#" class="text1"{text2}>...</a>
What does the {text2} do? Later on, this HTML is replaced with:
<a href="#" class="text1" {text2} style>...</a>
Is there a way I can retrieve the text2 value with jQuery?
In some cases that code is input in, so scripts can actually easily identify a the line. Or in some cases can be an indicator for a database to retrieve and store data once it has been pulled.
Or it could be invalid markup, doubtful if the person knows what they are doing.
But without any other information or variables it is hard to say. But the most common is access for scripts within Php, Javascript, and even C#. Cause they can parse the HTML document and manipulate it. If those braces are used, and it is incorrectly it will cause a parse error.
Hopefully that sort of clarifies it.
Update:
Yes, jQuery can find it. It is a form of Javascript. You could implement something such as:
$(function() {
var foundString = $('*:contains("{text1}")');
});
There is a vast amount of data that addresses this for more detail.
It does nothing in HTML. It's actually invalid markup. Looks like maybe you have a template system that finds and replaces that before it gets rendered to the browser.
I know that in jinja2, a python templating system, brackets contain commands to the template engine, either as:
Hello, {{varName}}
or:
<ol>
{%for l in varList%}
<li>{{l}}</li>
{%endfor%}
</ol>
That's in jinja, but jinja has similar syntax to django templates, and many other template engines probably copy django's syntax also.
its used in angular js and are called expressions {{expression}}
AngularJS is a JavaScript framework. It can be added to an HTML page with a tag.
AngularJS extends HTML attributes with Directives, and binds data to HTML with Expressions.
I am working on a django project (my first), and in one of my views, I have a sophisticated html snippet with JS weaved within it. I would like to reuse this "component" somewhere else in the same view. Is there a way of achieving this? Please let me know if this design is faulty to begin with?
Use the {% include '/my/common/template.html' %} templatetag.
Loads a template and renders it with
the current context. This is a way of
"including" other templates within a
template.
The template name can either be a
variable or a hard-coded (quoted)
string, in either single or double
quotes.
I know it's an old one but maybe someone is gonna have use of this answer.
There's also the inclusion tag. It's like the include tag, only you can pass it arguments and process it as a seperate template.
Put this in my_app/templatetags/my_templatetags.py:
#register.inclusion_tag('my_snippet.html')
def my_snippet(url, title):
return {'url': url, 'title': title}
and then my_snippet.html can be:
{{ title }}
then, to use this snippet in your templates:
{% load my_templatetags %}
{% my_snippet "/homepage/" "Homepage" %}
More info:
https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags-inclusion-tags
Not sure, if you like to reuse your HTML in different templates (rendered by different views). If so, look into Django's template inheritance mechanism:
The most powerful -- and thus the most complex -- part of Django's template engine is template inheritance. Template inheritance allows you to build a base "skeleton" template that contains all the common elements of your site and defines blocks that child templates can override.
You should try Django custom template tags. This way you will keep your snippets in an external file and then call them easily by something like {{ your_custom_tag }}. It's a very convenient method for working with reusable chunks of xhtml markup. You can even use arguments with these custom tags, something like {{ your_custom_tag|image:"logo.png" }}.
You can learn more about custom tags here.