how do I add the following string {{ cake }} to a view but have only have it displayed as {{ cake }}. Web2py tries to replace with a variable that doesn't exist. I just want to make use of double open {{ and close }} within the view HTML without web2py searching variables.
Is there an escape character that is needed?
thanks
One option is to wrap the opening delimiter in quotes inside a pair of template delimiters:
{{='{{'}} cake }}
Note, there is no need to wrap the closing delimiter because the template engine will only process it if there is an unmatched opening delimiter earlier in the template.
Another option is to define a helper function (preferably in a model file so it is available in all views), such as:
def wrap(content):
return '{{%s}}' % content
and in a template:
{{=wrap('cake')}}
Finally, if the issue is that you are using a Javascript framework (e.g., Vue.js) that uses the same template delimiters as web2py, you can dynamically (e.g., per controller action) change the web2py delimiters via response.delimiters. For example:
response.delimiters = ('%{', '}%')
Also, note that most Javascript frameworks allow you to specify custom delimiters as well, so you may find it easier to make the change there rather than in web2py.
Related
Currently I'm trying to create a macro. The macro will be used within a $list widget which will cycle through a collection of tiddlers (chosen as per certain filter criteria which themselves aren't relevant here).
Within the above $list widget, for each tiddler, the macro will go through all of the fields of the tiddler that have a certain prefix (which is "link_"). These fields contain as their value internet URLs.
Not only do I wish to display these URLs (for each tiddler) as a list, I wish them to act as hyperlinks to said URLs.
Now so far the below macro has worked for the moment:
\define myMacro(prefix:"")
<$list filter="[fields[]prefix[$prefix$]sort[title]]" variable="fieldName">
<$transclude field=<<fieldName>>/>
</$list>
\end
What the above does is simply print the value (the URL) of that field while making sure it also acts as a hyperlink to that particular URL.
BUT
I wish to improve this further. Instead of the text of those links being the link itself, I want it to be a custom text.
For eg:
https://en.wikipedia.org/wiki/Computer_programming
vs.
Computer Programming (hyperlink to the same page but with custom hyperlink text)
But doing the above is seemingly impossible with the above $transclude method unless there is a way of using the output of a widget itself as a value.
I've already checked something direct like:
[[Custom link name|<$transclude field=<<fieldName>>/>]]
or
<a href=<$transclude field=<<fieldName>>/> >Custom link name</a>
Doesn't work.
I've tried other methods too but they don't work. How do they not work?
Let's say there is a variable in that particular tiddler called list_1 and it's value is https://en.wikipedia.org/wiki/Computer_programming. I wish to use the https://en.wikipedia.org/wiki/Computer_programming as the href value of an <a> tag.
But with all the methods I've tried, at best I can access the value list_1 itself via <<fieldName>>.
Only the $transclude method itself allows me to use the value of list_1 itself (ie https://en.wikipedia.org/wiki/Computer_programming), but it doesn't allow you AFAIK to use it as a value in an another wikitext expression.
So how do I achieve my aforementioned objective? Is there a way to use the output of a widget itself as a value for another wikitext expression or is there some other way to accomplish my objective?
Thanks in advance.
not sure I understand your goal but this is definately wrong:
<a href=<$transclude field=<<fieldName>>/> >Custom link name</a>
you should use the <$link widget to create links and a filter for attribute values
<$link to={{{[[title]get<fieldName>]}}}>Custom link name</$link>
or
<$link to={{{[<variableWithTitle>get<fieldName>]}}}>Custom link name</$link>
Edit: added title to filter
Is it possible to generate a set of posts in _posts as Markdown files in a way that they are treated as if they had been manually created and therefore, available to the process of creating the site pagination? I found examples of how to generate pages in various places like this SO question, but they seem to put the rendered content in _site and displaying the {{ paginator.total_pages }} variable does not yield any value.
Yes its possible to add "dynamic" content using a generator plugin.
You can generate pages, posts, collection's items, static files, anything you want.
For the {{ paginator.total_pages }} returning nothing. The paginator variable will only be available in your pagination template and nowhere else.
So i have a collection called components. The components are a series of small HTML objects with some data in.
I want to pull these components into a page, and be able to pass overriding YAML frontmatter from the page into the component to determine a couple of things on the component.
Is this possible?
I'm pulling specific components onto a page using the following syntax:
{{ site.components | where:"component_name","event-title" }}
but i'd like to be able to do something like:
{{ site.components var-page-state="offline" | where:"component_name","event-title" }}
I chose to use a collection than a series of includes, as i need to loop through the collection and generate/render an index page of all of the components on it automatically.
EDIT:
So i want my component to be able to output a variable set on the page it's included on.
component.title.html:
<h2 class="title">{{ page.var-page-status }}</h2>
how can i convert the variables in ajax.
<li ng-repeat="item in newsItems | filter:q" style="background-color: white;">
{{item}}</br>
{{item}} displays data in the browser. but i want to transfer this item data to the scala side. the one with the #, because i need the item in:
#form(routes.Application.newItem({{item}})){....}
whenever i run this. it displays.
item not found.
what i want is a step or anything to convert this ajax data to the scala side variable.
You can't do that directly, keep in mind that JavaScript is client-side technology and Scala template is backend one. That means that Play compiles the view long, long before the client (and its JS) will see it.
You have 2 solutions:
Replace action attribute of form tag using JavaScript
You can also use Play's JavaScript routes to create url (also using javascript after page rendering)
In Jekyll/Octopress, how can I place the output of a tag inside another tag?
This is what I want to do (using Octopress's img tag):
{% img {% PluginThatOutputsAURL %} %}
If I do that I get this error:
Error processing input, expected syntax: {% img [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | “title text” [“alt text”]] %} %}
Is it possible to do this? What would be the right syntax to do so?
Jekyll/Octopress uses Liquid Templates to parse these things.
As far as I know, you can't call two functions within a tag like that. You can however specify variable names in tags:
using Liquid variables inside of a liquid tag call
I tried Googling a bit and didn't see anything pop up for calling two functions within one tag.
IMO, I'd recommend creating a custom tag to do exactly what you want. I have created several custom plugins to Octopress because I needed such customization. The plugins, which is just Ruby. is pretty straight forward.
So, copy the existing img_tag.rb and call it, mycustom_img_tag.rb or whatever, and perform your magic within the render() method.
For example, here's my HTML5 audio player tag I wrote where I needed to know what extension the audio file was (specified in the url) in order to specify the content type:
https://github.com/eduncan911/eduncan911.github.io/blob/b89f47cd86c37f2cfb5c3093612fe0a049808325/plugins/audio_tag.rb
^- NOTE: It is incomplete and all the options doesn't work as I specified. You can see what works in the render() section, where I just parse the data-* attributes manually (I ran outta time and just made it work).
I basically used two other plugins as a template and created this one.
You have access to the entire Octopress methods and variables in your plugin - there are no restrictions to the entire code base.