specify string in title while using groovy template for play 1.2.5 - playframework-1.x

I am using the groovy template for play 1.2.5. I need to append a string to the title tag for the html page. However, the option I tried below does not result in the value to be displayed - I am wondering whether the issue is related to escaping or faulty logic on my part (which I'm quite capable of).
#{set title:'ABCD | ${object.property}' /} // object.property has a valid String value
Thanks in advance!

While setting the title, the title is already within the "#{}" tag. If passing another variable, one does not need to use the ${} format - simply ensure that you pass in the variable needed without the ${} and outside the '' characters. For instance:
#{set title:'ABCD | ' + object.property /}
This worked (as long as object.property is valid). Unless I am mistaken, you can also use the
object?.property format to avoid cases where the object might be null. Hope it helps!

Related

SALESFORCE : Email template conditional field not working

I am currently working on an email template, and I can't seem to be able to reference a field in a IF statement.
The current line I'm having trouble with:
{!IF(Demande_CPT__c.Reponse_Partenaire__c ="Place disponible",”{!Demande_CPT__c.Date_expiration_option__c}”,"notfrench")}
We tried :
{!IF("{!Demande_CPT__c.Reponse_Partenaire__c}" !="Place disponible",”{!Demande_CPT__c.Date_expiration_option__c}”,"notfrench")}
{!IF("{!Demande_CPT__c.Reponse_Partenaire__c}" !="Place disponible",Demande_CPT__c.Date_expiration_option__c,"notfrench")}
but nothing seems to work...
The field evaluates to true and we can get a string to show up but not the field reference. I hope I make sense.
If you have any idea !
Thank you
You already are in the "merge field syntax" of {!text has special meaning here}, you don't need another {! inside it. And your quote signs are wrong, they need to be plain "", not fancy „“. If you edited the template in MS Word it likely injected some rubbish in it with hidden <span></span> tags that also can completely mess the field merging up.
Try with {!IF(Demande_CPT__c.Reponse_Partenaire__c = "Place disponible",Demande_CPT__c.Date_expiration_option__c,"notfrench")}
What is it, normal template or Visualforce? From what I remember normal templates are limited and for IFs you might have to waste a formula field... But Visualforce should work OK
Some more help: https://trailblazers.salesforce.com/answers?id=90630000000gpkYAAQ

Using htmlspecialchars dynamic title as a parameter for a shortcode

I am using post title as a shortcode parameter but it does not completely work clean when a page title has & in it.
'Communications & Media Coordinator' .
I am trying to do htmlspecialchars but it still outputs 'Communications' only.
$jobtitlestr = htmlspecialchars($jobtitle);
echo do_shortcode('[gravityform id="1" field_values="job_title=' . $jobtitlestr . '&job_location=' . $locationtitle . '&list_count='" ajax="true" tabindex="1"]');
Thanks
Assuming this shortcode is part of a GET query, the '&' is used as a separator between terms and explains why your title is getting cut off.
In PHP, htmlspecialchars translates certain characters to their equivalent HTML entities. The '&' character will become '&' so will still provide a problem if you're using it as part of a URI.
I suspect the function you need instead is urlencode. You will have to run it through urldecode on the other side too.
https://www.php.net/manual/en/function.urlencode.php

Remove trailing / from URL in Jinja2 (regex?)

I have a template for an MkDocs site, which uses Jinja2. I am trying to add a link to a PDF version of each page. The PDF always has the same name as the markdown file. So I am trying to add a link in the template that will automatically target the correct PDF for each page. This feels cleaner than having the writers add a manual link to every page.
Download
The above is almost correct, but there is a '/' at the end of all the URLs. Meaning the result is:
page/url/slug/.pdf
Neither MkDocs nor Jinja seem to provide a filter to remove trailing slashes, so I am wondering if it's possible to use regex to remove it. I believe that would be as simple as \/$? However, I can't see from the docs how to apply a regex filter in Jinja?
You can do something like this:
{{ "string/".rstrip("/") }}
Worked for me.
So I found a workaround for my specific case, but it's nasty:
<a href='{{ config.site_url }}{{ page.url | reverse | replace("/", "", 1) | reverse }}.pdf'>Download</a>
Prepend the site URL
Get the current page URL, reverse it, use replace with the optional count parameter to remove the FIRST '/', then reverse it again to get it back in the right order
Append '.pdf'
According to one of the answers to the question linked by Jan above, you can't simply use regex in Jinja2 without getting into custom filters.
Download
where $ is the end of the line / end of the string.
Therefore, /$ means the / at the end.

Django: Refer to an url name in a template and passing parameter

I know you can refer to a urlname in a template so that you don't need to hardcode your url links in your templates whenever you want to change them.
For example in a template, I use:
The link
My problem is, if I want to pass a more complex parameter to be used in the url regex. In my case, I want to pass a concatenation of two strings separated by an "_". Those strings come from Python objects and I don't get how to do that. Let's say for example, those strings are the firstname and lastname of a user.
I tried:
The link
And others tricks but none worked.
Can someone help?
Simply, you don't.
You either adjust your url to have two capture groups (which would also require a slight change to the view)
url(r'(?P<first_name>\w+)_(?P<last_name>\w+)/$', view_name, name='url_name')
{% url 'urlname' user.firstname user.lastname %}
Or you just find a different url that suffices.
Please have a look at this thread. The good answer for you, assuming you're using posititionnal arguments :
The link
Assuming your url conf is like so :
url(r'^urlname/(?P<parameter>(catching regexp))$',...)

Is is possible to html encode output in AppEngine templates?

So, I'm passing an object with a "content" property that contains html.
<div>{{ myobject.content }}</div>
I want to be able to output the content so that the characters are rendered as the html characters.
The contents of "conent" might be: <p>Hello</p>
I want this to be sent to the browser as: &amplt;p&ampgt;Hello&amplt;/p>
Is there something I can put in my template to do this automatically?
Yes, {{ myobject.content | escape }} should help (assuming you mean Django templates -- there's no specific "App Engine" templating system, GAE apps often use the Django templating system); you may need to repeat the | escape part if you want two levels of escaping (as appears to be the case in some but not all of the example you supply).
This is Django's django.utils.html.escape function:
def escape(html):
"""Returns the given HTML with ampersands, quotes and carets encoded."""
return mark_safe(force_unicode(html).replace('&', '&').replace('<', '&l
t;').replace('>', '>').replace('"', '"').replace("'", '''))
Also, see here.