SALESFORCE : Email template conditional field not working - if-statement

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

Related

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.

Django Grappelli Rearrange Inlines id override

According to the docs:
http://django-grappelli.readthedocs.org/en/latest/customization.html#rearrange-inlines
The two classes for the placeholder are important. First, you need a class placeholder. The second class has to match the id of the inline–group.
All's well and good, I was able to set up my inlines fine, my issue is now - where does grappelli get the "id of the inline group" I can't find any reference, and pouring through the source code is offering me no solace.
Simply, I want to change the element-id that grappelli is using. Currently, it looks to me that it is taking the object name itself and converting to a lowercase name and appending set to the end. Do we have access to override the "id of the inline-group"?
Also, I am not 100% sure exactly how (or where) grappelli is doing this, it is definitely not documented... at all in fact.
Any help would be much appreciated.
It is the id of the inline element on HTML page. You can check the id of the default HTML inline element.
<div id="[related_name of ForeignKey]-group">
For example:
If in model "MyModel2", you have a ForeignKey like this:
my_model_1 = models.ForeignKey(MyModel1, related_name='my_model_2')
Then the id should be "my_model_2-group".
The id of the inline group is set in grappelli/templates/admin/edit_inline, in stacked.html line 5, or tabular.html line 6 (depending on which type of inline you're usng):
id="{{ inline_admin_formset.formset.prefix }}-group" >
You can override this by copying the file (stacked.html or tabular.html) into your template directory and setting the variable "template" to the file's new location e.g.:
# admin.py
class MyModelInline(admin.StackedInline):
template = 'path/to/stacked.html'
...
Then edit whatever you want in e.g. stacked.html.
I don't know if this is the best-practices way of doing this, but it's similar to what's done in the django tutorial.

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!

How can I make a verbose template tag in Django?

I have the following inclusion tag:
#register.inclusion_tag('bouts/fighter/_fighter_bout_list.html')
def fighter_bout_list(list, header, fighter, has, empty):
return {
'list' : list,
'header': header,
'fighter': fighter,
'has' : has,
'empty' : empty,
}
To use it, I can include the following in my template:
{% fighter_bout_list wins "Wins" fighter "beat" "has no wins!" %}
However, I would like to make my tag readable so it is easier to see what the code is doing. Ideally, I'd like to use this for my input:
{% fighter_bout_list list=wins header="Wins" fighter=fighter has="beat" empty="has no wins!" %}
What is the best way (or even just a good way!) to do this?
Changing the Django template system to do what you want would be extremely difficult; if you want to do that, start by completely understanding the django.template module. Frankly, I wouldn't recommend creating a tag that used a different way of handling parameters than all of the other existing tags -- it would prove confusing to the users that have to work with the tags.
But if you insist on doing this anyways, you just need to have your custom template tag parse its parameters individually to provide the service. Something like this should do the trick:
def fixit( argument ):
"""Strip off any leading 'word=' noise words from argument"""
result = argument.split('=')[-1]
if result[0] == '"' and result[-1] == '"':
result = result[1:-2]
return result
#register.inclusion_tag('bouts/fighter/_fighter_bout_list.html')
def fighter_bout_list(list, header, fighter, has, empty):
return {
'list' : fixit(list),
'header': fixit(header),
'fighter': fixit(fighter),
'has' : fixit(has),
'empty' : fixit(empty),
}
Edited
This code is still positional -- I'm not suggesting that you can use this to do true keyword arguments. I added code to deal with the presence of quotes, but I still haven't tested this -- it's just a suggestion.
Again, I'd strongly recommend against this approach. The point behind a template tag is to do something that can't be done easily with the existing template tags, but it's still part of a template, and is really there to be a tool for someone technical enough to use an HTML editor. I'm trying to picture a use case for your proposed tag where it will be used more than a couple of times in a site. A little documentation and an example would be a lot cheaper than trying to implement keyword arguments for a template tag in a system that doesn't use keyword arguments.

Why won't Django auto-escape my <script> tags?

My Django app has a Person table, which contains the following text in a field named details:
<script>alert('Hello');</script>
When I call PersonForm.details in my template, the page renders the script accordingly (a.k.a., an alert with the word "Hello" is displayed). I'm confused by this behavior because I always thought Django 1.0 autoescaped template content by default.
Any idea what may be going on here?
UPDATE: Here's the snippet from my template. Nothing terribly sexy:
{{ person_form.details }}
UPDATE 2: I have tried escape, force-escape, and escapejs. None of these work.
You need to mark the values as | safe I think (I'm guessing that you're filling in the value from the database here(?)):
{{ value|safe }}
Could you post a sample of the template? Might make it easier to see what's wrong
[Edit] ..or are you saying that you want it to escape the values (make them safe)? Have you tried manually escaping the field:
{{ value|escape }}
[Edit2] Maybe escapejs from the Django Project docs is relevent:
escapejs
New in Django 1.0.
Escapes characters for use in JavaScript strings. This does not make the string safe for use in HTML, but does protect you from syntax errors when using templates to generate JavaScript/JSON.
[Edit3] What about force_escape:
{{ value|force_escape }}
...and I know it's an obvious one, but you're absolutely certain you've not got any caching going on in your browser? I've tripped over that one a few times myself ;-)
Found the problem. The JSON string I'm using to render data to some Ext widgets is the culprit. Big thanks to Jon Cage. Answer accepted despite the problem being caused by another source.