Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

How to count number of slashes in URI?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
dougmcc1
Smarty n00b


Joined: 20 Sep 2015
Posts: 2

PostPosted: Sun Sep 20, 2015 4:30 am    Post subject: How to count number of slashes in URI? Reply with quote

How do I use smarty to count the number of slashes in the URI and store it in a variable?

Here is the php code that I need to convert to smarty:

$url_path = $_SERVER['REQUEST_URI'];
$count_of_slashes = count(explode('/', $url_path))-1;
echo $count_of_slashes;

Thanks!
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Sep 20, 2015 10:48 pm    Post subject: Reply with quote

WHY do you need to do it in Smarty to begin with?
Are you trying to pull business logic into presentation layer or what?
Back to top
View user's profile Send private message
dougmcc1
Smarty n00b


Joined: 20 Sep 2015
Posts: 2

PostPosted: Mon Sep 21, 2015 5:31 am    Post subject: Reply with quote

Because the software I'm working its requires it, or else I wouldn't ask Very Happy

Do you or anyone else have an answer or more questions?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Sep 21, 2015 6:06 am    Post subject: Reply with quote

Write a string modifier (filter) which would return the number of slashes in a given string.
Just, don't use explode(), or I'll explode() your head.

Refs
http://www.smarty.net/docs/en/language.modifiers.tpl
http://www.smarty.net/docs/en/plugins.modifiers.tpl
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Sep 22, 2015 12:54 am    Post subject: Reply with quote

Code:
{$count = $smarty.server.REQUEST_URI|substr_count:'/'}


use function substr_count as modifier
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP