Hi. How can I use regexps with “{” and “}” in TPL files?
In Smarty, you will need to quote {
and }
. This can be done by wrapping the entire statement in {literal}
tags, or by simply replacing the specific character by {ldelim}
or {rdelim}
.
Unfortunatly it dows not work.
I get an error “syntax error undefined token ‘’^\d{ldelim”
The code is very simple:
{foreach from=$entry item=value}
{if (preg_match(’^\d{ldelim}9{rdelim}[\d|X]$’ , $value))} 1
…
…
{/if}
You probably can’t nest smarty tags like that (the {ldelim}
is inside the {if }
. I’d also advice loosening some of the mixing of PHP logic at the Smarty level. Better would be to perform the preg_match() calculation outside of the template, and pass it in as a property of the $entry
elements.
We’re veering a bit from OJS-specific questions to general Smarty templating questions, however. Have you tried your question on some of the Smarty-specific forums elsewhere?
It is a new theme for me. But it is a common roblem foe OHS I think. I have both OJS and OHS, but 1st is very complex and it is very difficult to do something with OJS. And OHS is very simple and I can find and solve many of my problems. For examle you can look here:
Many identifiers are not URLs, for example ISBN. Many other fields are URLs, for example dc.rights.uri.
I can make a simple patch for strings 35-40 to make all values wich match URL to be links and I do it. This code was in template, not in php file, and I only fix it.