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
Related
I generate pdf (latex) from restructured text using python sphinx (1.4.6) .
I use narrow table column headers with texts like "stuff/misc/other". I need the slashes to be breakable, so the table headers don't overflow into the next column.
The LaTeX solution is to use \BreakableSlash or \slash where necessary. I can use python code to replace all slashes:
from sphinx.util.texescape import tex_replacements
# \BreakableSlash needs package hyphenat to be loaded
tex_replacements.append((u'/', ur'\BreakableSlash ') )
# tex_replacements.append((u'/', ur'\slash ') )
But that will break any URL like http://www.example.com/ into something like
http:\unhbox\voidb#x\penalty\#M\hskip\z#skip/\discretionary{-}{}{}\penalty\#M\hskip\z#skip\unhbox\voidb#x\penalty\#M\hskip\z#skip/\discretionary{-}{}{}\penalty\#M\hskip\z#skipwww.example.com
or
http:/\penalty\exhyphenpenalty/\penalty\exhyphenpenaltywww.example.com
I'd like to use a general solution that works in both cases, where the editor of the documentation can still use normal ReST and doesn't have to worry about latex.
Any idea how to get classic slashes in URLs and breakable slashes everywhere else?
You have not really given data and source code and only asked for an idea, so I take the liberty of only sketching a solution in pseudo code:
Split the document into a list of strings at each position of a space using .split()
For each string, check whether it is an URL by comparing its left side to http:// (and maybe also ftp://, https:// or similar tags)
Do replacements, but only in strings which are no URLs
Recombine all strings including the spaces again, using a command such as " ".join(my_list)
One way to do it, might be to write a Transform subclass. And then use add transform in setup(app) to use it in every read.
I could use DefaultSubstitutions from transforms.py as template for my own class.
I know how to print double curly braces in Laravel: #{{ }}.
But how can I print triple curly braces? My first thought of adding an # before does not work, Laravel still tries to interpret it.
Is there an easy way without encoding the braces to HTML entities?
Update
Very recently, a pull request was merged that fixes this problem!!
As of Laravel 5.1.7 it is possible to use the # sign as expected:
#{{{ ... }}}
Original Answer
The least ugly workaround I found up until now is to escape the first two brackets as normal and adding an invisible between them and the third bracket:
#{{{test}}}
I'll investigate further and update this answer if I find something better...
This is the easiest way. Use HTML entities to escape curly braces. Tested in Laravel 5.
See here for the list of HTML entities. HTML Entities
Code
{{{text}}}
Output
{{{text}}}
Use this if you just want to print them:
{{ '{{{' }}
One more way is as following
{#{{Text}}}
I ran into the same issue trying to render some raw HTML using Vue.js in laravel 4.2. For me the easiest solution was to just to use a simple php echo statement in the blade template:
<?php echo '{{{ text }}}'; ?>
Did the trick for me.
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.
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.
I'm still struggling with getting jqgrid's viewGridRow function to handle grids that have column names that include spaces. I came up with a hack to replace spaces with underscores but was told that that I should be using jqID instead. Specifically,
If you want modify the code you should better use $.jgrid.jqID instead of replacement of blanks to undescores. The function $.jgrid.jqID are used in the most places of jqGrid code, but still not everywhere. The problem it very easy. It one have meta-characters as the part of id and one want to use the id as a part of the jQuery selector one have to escape the characters. The method $.jgrid.jqID do exactly the job.
Upon looking at the source code inside grid.base.js, I see that the function is defined as
$.extend($.jgrid,{
jqID : function(sid){
return String(sid).replace(/[!"#$%&'()*+,.\/:;<=>?#\[\\\]\^`{|}~]/g,"\\$&");
}
});
which leads me to believe that it should be perhaps used in the beforeProcessing() function to modify the cell IDs? Regardless, I don't see that the regex, as it currently exists, specifically handles spaces.
Oleg, if you're out there, help!!! :)
D'oh!! As soon as I hit submit, I realized that Oleg meant to modify the jqID function to add spaces to the regex string. That seems to do the trick.