UDT inside a another tag?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

UDT inside a another tag?

Post by jmansa »

Is it possible to insert a UDT inside another tag? I've installed a multilanguage site and was having trouble changing headlines made in my template so I came up with this solution.

my urls look like this:
www.mypage.com/index.php/uk/welcome or www.mypage.com/index.php/da/velkommen

I made a UDT to get the language out of the current url like this:
UDT = current_url

Code: Select all

function selfURL() {
	$s = empty($_SERVER["HTTPS"]) ? ''
		: ($_SERVER["HTTPS"] == "on") ? "s"
		: "";
	$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
	$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
		: (":".$_SERVER["SERVER_PORT"]);
	return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) {
	return substr($s1, 0, strpos($s1, $s2));
}
This looks at my url and gets the 2 letters (uk, da) for use later.
I then put that in top of my templatebody.

Now, I had a headline for my news in my template like this:

     
         News
          {news number="3" detailpage="news"}
     
I have created my page in both english and danish and now wanted the "News" headline to change to the dansih language "Nyheder" when I went on the danish version of the site. This was done by making a UDT like this:
UDT = newshead

Code: Select all

$url = selfURL(); 
$last_slash = strrpos($url, "/"); 
$temp = substr($url, 0, $last_slash); 
$second_last_slash = strrpos($temp, "/"); 
$page = substr($url, $second_last_slash+1, $last_slash-$second_last_slash-1);

if($page == 'da') {  
echo 'Nyheder'; } 
if($page == 'en') { 
echo 'News'; }
I then inserted the {newshead} instead of news and viola... The header changes

Now here comes the tricky part and my question (at last)

I now want the news to change category when I change language, but how do I do that. I have tryid this but no can do...

I made a UDT called newscat like this:

Code: Select all

$url = selfURL(); 
$last_slash = strrpos($url, "/"); 
$temp = substr($url, 0, $last_slash); 
$second_last_slash = strrpos($temp, "/"); 
$page = substr($url, $second_last_slash+1, $last_slash-$second_last_slash-1);

if($page == 'da') {  
echo 'news_DK'; } 
if($page == 'en') { 
echo 'news_UK'; }
I then tryid to insert into my template like this...
{news number="3" detailpage="news" category="{newscat}"}
but that didnt work... Can somebody please help me with this problem...
alby

Re: UDT inside a another tag?

Post by alby »

jmansa wrote: ............
I then tryid to insert into my template like this...
{news number="3" detailpage="news" category="{newscat}"}
but that didnt work... Can somebody please help me with this problem...
Substitute echo with return in:

Code: Select all

.......
if($page == 'da') {  
echo 'news_DK'; } 
if($page == 'en') { 
echo 'news_UK'; }
And in template:

Code: Select all

........
{capture name=newscat}{newscat}{/capture}
........
........
{news number="3" detailpage="news" category="$smarty.capture.newscat"}
Alby
Last edited by alby on Wed May 23, 2007 2:45 pm, edited 1 time in total.
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: UDT inside a another tag?

Post by jmansa »

Thanks alot, but I'm not quite shure what or how you mean about using return instead of echo... Can you give an example?!
alby

Re: UDT inside a another tag?

Post by alby »

jmansa wrote: Thanks alot, but I'm not quite shure what or how you mean about using return instead of echo... Can you give an example?!
Forgot my item, I thought to other  ::)
Follow template sample ...

Alby
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: UDT inside a another tag?

Post by jmansa »

I just inserted the template suggestion and did nothing with the UDT, but I get an smarty error... Why?
string(125) "Smarty error: [in template:19 line 93]: syntax error: $smarty. is an unknown reference (Smarty_Compiler.class.php, line 2115)"
Where do I go wrong?
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: UDT inside a another tag?

Post by jmansa »

Sorry... Found the problem... The "" !
Post Reply

Return to “CMSMS Core”