.tpl file and %%. Is this smarty? - smarty

I have a .tpl file which has %% variables in it.
Example:
%%GLOBAL_Error%%
Is this a smarty template engine file?
I want to check if this variable is not empty, but I can't do this with regular smarty syntax.
{if isset($GLOBAL_Error) }
How can i do this?
I got response that this is Twig template engine :S

By default, smarty use { and } as delimiters. So, you can write code:
{if $GLOBAL_Error}{/if}
But delimiters could be changed to %% and code must be in such form:
%%if $GLOBAL_Error%%%%/if%%
See also: http://www.smarty.net/docsv2/en/language.escaping.tpl

It might be, but it might not be. Smarty tag delimiters are configurable, so it's possible the developer set them to %% and %%. GLOBAL_Error may not be a variable, but a function call with no parameters. In that case, you'd need something like:
%%if (%%GLOBAL_Error%%) %%
That's some pretty ugly syntax though. It could be anything, maybe a string token for some search/replace before or after the template is compiled. If you're already using Smarty with standard delimiters, then it's unlikely that %%GLOBAL_Error%% is meant to be parsed by Smarty - it might even be a mistake or relic of old code. The only way to know for sure is to ask the author or just look at the codebase.

Related

How to stop go html/template from escaping a path (tried .HTML .JS etc.)

I am using the html/template functionality to assemble a page and on of the variables I'm supplying to the template is URI in the form "/some/path/etc" which is used as a parameter to a JS function called in a onClick="..".
No matter what, the string used in this configuration will be escaped with backslashes : "\/some\/path\/etc"
As you can see in the playground example below, I tried all the .HTML(), .JS() etc. functions but nothing seems to stop the escaping.
See Go Playground example here: https://play.golang.org/p/2gdghTpQHKP
How can I get this URI "as is" into the template result?
Thanks to mkopriva for his comment.
As far as I could see there is no way (as mkopriva mentioned) to handling a HRML attribute value fragment in a Go HTML template.
So the options are:
Leave it as is (it seems that at least in my use case the URI even works in the further processing with the escaped forward slashes)
first concatenate the complete attribute, so that the "HTML Attribute" way will accept it
Write a construction function that takes parts and assembles the final attribute value inside the template execution
Hardcode the value in some form

Joomla INI translation

I need to translate in my ini file a word that has a "()" or an "/" sign but it seems to brake when I do it.
eg.
sometext(text)="otherLanguagetext(text)" <-- this causes an error in the ini file an brakes all translations.
sometext/text = "someOthertext/text" <-- Broken also
having spaces work correctly:
Some text="Some text1" <--Works
The fact is that the original language is database generated and doesn't have any translation tag or something like joomla translation tag.
I just type the word I want to translate in this way.
I searched for an ini editor that might fix this out automatically (e.g place '/' or something ) but I had no luck on this.
Your example key's are invalid. INI files by definition can not have any of these characters: ?{}|&~![()^" in the keys.
Note: There are reserved words which must not be used as keys for ini
files. These include: null, yes, no, true, false, on, off, none.
Values null, off, no and false result in "". Values on, yes and true
result in "1". Characters ?{}|&~![()^" must not be used anywhere in
the key and have a special meaning in the value.
— http://www.php.net/manual/en/function.parse-ini-string.php
Joomla language files also have their own specification, which if not followed will cause an error when Joomla loads and parses the language file.
In INI files and Joomla language files the value also has special interpretations for specific characters and requires escaping for the use of some characters like double quotes etc.
Finally, Joomla has language overrides that allow the end user to override any string set by the core software or third party extensions which also affect the way keys are translated.
Try to use backslash before those symbols like this:
"otherLanguagetext\(text\)"
"someOthertext\/text"
P.S. you cannot use ANY special symbols in your constants! Try to name them something like this:
OTHER_LANGUAGE_TEXT
SOME_OTHER_TEXT
Try this,
SOME_TEXT = "otherLanguagetext(text)"
SOME_OTHER_TEXT = "someOthertext/text"
Hope it works

How to output ${expression} in FreeMarker that contains HTML AS HTML

In my data model myVar contains <b>hello</b> and when I bring it like this ${myVar} the output I get is literally <b>hello</b> rather than hello.
Any idea how to correct this?
Certainly you have HTML escaping on, so try <#noescape>${myvar}</#noescape>.
Update: Since 2.3.24 a new kind of auto-escaping was introduced, which doesn't use #escape, and hence nor #noescape. When that's used, write ${myvar?no_esc} to avoid escaping. Or, you can put the value into the data-model already as a TemplateHTMLOutputModel (created with HTMLOutputFormat.fromMarkup(myString)), and then FreeMarker will know without ?no_esc that it need not be escaped.

Ignore MediaWiki whitespace

How do I ignore whitespace on a wiki template?
So for example, I create a template called Hello. Inside that, I put {{{text}}}.
So now when I put {{Hello |text=Hi Bye}} on a page, and save it, the page says. "Hi Bye" (of course).
I want it to display "HiBye", not "Hi Bye". What do I put in the template to do that?
To remove characters inside the value in a template (whitespace or other), you have to search and replace. You can install the extensions ParserFunctions, to get access to parser functions like replace, and then to something like this:
{{#replace:{{{text|}}}| |}}
If your MediaWiki is version 1.18 or newer (if it's not, you should upgrade anyway), ParserFunctions is already bundled with your installation. Then you just have to enable it, like this in LocalSettings.php:
require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );
$wgPFEnableStringFunctions = true;
On a side note, whitespace characters in the beginning and end of a variable is always stripped, if using named parameters. In other words: {{Hello |text= Hi Bye }} is equal to {{Hello |text=Hi Bye}}. On the other hand, {{Hello | Hi Bye }} is not equal to {{Hello |Hi Bye}}. Advanced templates sometimes make clever use of this difference. The replace function will work in both cases, of course.

Smarty Remove Everything after specific character

I have this:
{$videos[i].videofile}
and my $videos[i].videofile equals to 12931024123.mp4
I want to remove everything after the dot. I have already tried |strstr:'.':true, but it does not work (wrong parameters count).
NO PHP NEEDED. Must be done with Smarty functions in the template.
Not really the cleanest solution but you asked specifically for it: you could simply use PHPs substr as a modifier:
{$videos[i].videofile|substr:0:-4}
This will return 12931024123

Resources