Using htmlspecialchars dynamic title as a parameter for a shortcode - htmlspecialchars

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

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

Regex Custom Redirect in Blogger for every archive.html

I need to create a regex Custom Redirect in Blogger. The purpose is to redirect all HTML archives to somewhere else.
Currently I'm using the following in Settings / Search preferences / Custom Redirects:
From:/2018_11_21_archive.html
To:/p/somewhere_else.html
Permanent:Yes
The problem is that this method requires to add every date, and that's not acceptable.
/2016_10_21_archive.html
/2016_10_22_archive.html
/2016_10_23_archive.html
/2017_07_10_archive.html
/2017_07_10_archive.html
/2017_07_10_archive.html
/2018_11_21_archive.html
/2019_11_21_archive.html
...
So far I've tried this regex with no success:
From:/2018_(.*)
To:/p/somewhere_else.html
Permanent:Yes
Blogger custom Redirects does not support regex.
But I have a solution for you, use this code, and put it after <head>
<b:if cond='data:view.isArchive and data:view.url contains "_archive"'>
<b:with value='"https://www.example.com/p/somewhere_else.html"' var='destination'>
<script>window.location.replace("<data:destination/>")</script>
<noscript><meta expr:content='"0; URL=" + data:destination' http-equiv='refresh'/></noscript>
</b:with>
</b:if>
You have to escape the "/" character! Just insert a "\" before.
This line must be like this:
From:\/2018_.*
But be aware that this way only /2018_11_21_archive.html will match.
If you need ALL dates as you mentioned, I recommend this regex below:
\/([12]\d{3}_(0[1-9]|1[0-2])_(0[1-9]|[12]\d|3[01]))_archive\.html

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.

New Line on Django admin Text Field

I am trying to create a blog o django where the admin posts blogs from the admin site.
I have given a TextField for the content and now want to give a new line.
I have tried using \n but it doesn't help. The output on the main html page is still the same with \n printing in it. I have also tried the tag and allowed tags=True in my models file. Still the same. All the tags are coming as it is on the html page.
My Django admin form submitted:
The result displayed in my public template:
You should use the template filter linebreaks, that will convert the reals \n (that means the newline in the textarea, not the ones you typed using \ then n) into <br />:
{{ post.content|linebreaks }}
Alternatively, you can use linebreaksbr if you don't want to have the surrounding <p> block of course.
After searching the internet and trying different Django Template Filters, I came across one specific filter, SAFE.
For me, LINEBREAKS filter didn't work, as provided by #Maxime above, but safe did.
Use it like this in your html template file.
{{post.content|safe}}
To have a better understanding of SAFE filter, i suggest reading the documentation.
{{post.content|linebreaks}}
This will make the line in the textbox appear as it is without using \n or \.
{{post.content|linebreaksbr}}
Besides the newline function in your CSS Declaration will work too.

specify string in title while using groovy template for play 1.2.5

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!