开发者

Custom smarty function without identifiers?

开发者 https://www.devze.com 2023-03-04 19:08 出处:网络
Is it possible to create smarty functions that accept shorthands or, more specifically, variables without identifiers?

Is it possible to create smarty functions that accept shorthands or, more specifically, variables without identifiers?

I have a function which takes an object and returns a string; I'm currently writing:

{myFunc source=$object}

I wan开发者_开发问答t to be able to write {myFunc $object} without smarty squawking about missing identifiers, but I don't even know where to begin. It's also entirely possible that I'm missing some fundamental fact which makes this impossible. If that's the case, I'd like to know that too.


Without knowing what myFunc's purpose would be, I believe a modifier plugin could be what you are looking for. These are great for taking a string and formatting in another way, like taking a timestamp and formatting it in any way wanted.

Variable modifiers can be applied to variables, custom functions or strings. To apply a modifier, specify the value followed by a | (pipe) and the modifier name. A modifier may accept additional parameters that affect its behavior. These parameters follow the modifier name and are separated by a : (colon). Also, all php-functions can be used as modifiers implicitly (more below) and modifiers can be combined.

Source

Then in your template it would look like

{$object|myFunc}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号