Hailwood
Hailwood

Reputation: 92581

Smarty, truncate string on string?

I have a php blog,

In the blog a user can enter {split} where they wish the content to be split for snippets etc.

Then, in the smarty template, if I want to display the pull post I just use {$content|replace:'{split}':''}

But the other one I want to be able to do is have the content finish at {split}

Something like {$content|stop_at:'{split}'|strip_tags}

Is there a modifier that exists that implements something like this?

Upvotes: 0

Views: 1275

Answers (1)

Adam
Adam

Reputation: 7900

Sure use regex_replace. This should work:

{$content|regex_replace:"/(.*)({split}.*)/i":"\1"|strip_tags}

That will capture everything up to {split} into the first backreference (\1) and allow you to lose all the rest of the variable. Do not have my Smarty setup at the moment (was actually just getting to that), but the concept works in PHP.

Upvotes: 1

Related Questions