Topic: <h1>[*longtitle*]</h1> and PHP if  (Read 1862 times)

Pages: [1]   Go Down

#1: 2-Feb-2009, 08:23 PM

Morten
Posts: 38

WWW
Hi
If I write <h1>[*longtitle*]</h1> in my template and donīt use the longtitle my site will print an empty <h1></h1> 
Can I write something like : php if longtitle ........

I donīt know anything about PHP!

Hope you understand my English!

#2: 2-Feb-2009, 08:34 PM


mrhaw
Posts: 2,237

modx == freedom

WWW
This can be done with PHx ---> http://modxcms.com/PHx-1006.html
[*longtitle:isnot=``:then=`<h1>[*longtitle*]</h1>`:else=``*]
« Last Edit: 2-Feb-2009, 09:50 PM by mrhaw »
My playground: http://4up2date.info | Twitter: mrhaw
---> Check out: ReadSpeaker webReader Plugin | Support/Comments Thread

--=[ MR. HAW ]=--

#3: 2-Feb-2009, 08:40 PM

Testers

dev_cw
Posts: 4,218

WWW
This may work for you as well without using PHx (although PHx is great if you do not know PHP)
Code:
<?php
/* [!myField? $field=`[*pagetitle*]`] */

$field = isset($field) ? "<h1>".$field."</h1>" "";
return 
$field;

?>

There are more sophisticated methods but this should work and is easy to understand since it does not use the modx api. Simply use the snippet [!myField? $field=`[*pagetitle*]`] and change the field placeholder to be whatever you want. You can edit the output but changing "<h1>".$field."</h1>".

Note:  We are using the Ternary Operator to do the logic.
Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

Something is happening here, but you don't know what it is.
Do you, Mr. Jones?  -  [bob dylan]

#4: 2-Feb-2009, 09:25 PM

Coding Team

BobRay
Posts: 6,124

WWW
This may work for you as well without using PHx (although PHx is great if you do not know PHP)

Here's a slightly simpler (but less flexible) version:

Put this in your template where the longtitle would go:

Code:
[!LongTitle!]

Then create a snippet called LongTitle and paste in this code:

Code:
<?php
$field 
$modx->documentObject['longtitle']
return empty(
$field)? "" '<h1>'.$field.'</h1>'
?>

The last line is equivalent to this:

Code:
if (empty($field)) {
   return "";
} else {
   return '<h1>'.$field.'</h1>';
}
And here's another way using a placeholder (just to show how flexible MODx is):  Wink

In your template:

Code:
[!LongTitle!]
[+my_longtitle+]

In the snippet:

Code:
<?php
$field 
$modx->documentObject['longtitle']
$modx->setPlaceholder('my_longtitle', empty($field)? "" '<h1>'.$field.'</h1>'); 
?>


I hope this doesn't confuse you too much. Feel free to ask questions if you run into trouble.  Smiley




MODx info for newbies: http://bobsguides.com/MODx.html

#5: 3-Feb-2009, 08:01 AM

Morten
Posts: 38

WWW
wauw .... almost too much information for me!
Tkanks

"This can be done with PHx" ....... great i works for me
« Last Edit: 3-Feb-2009, 08:32 AM by Morten »

#6: 3-Feb-2009, 08:23 AM

Testers

dev_cw
Posts: 4,218

WWW
wauw .... almost too much information for me!
Be carefull for what you ask around here, the community takes answering questions seriously  Wink
Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

Something is happening here, but you don't know what it is.
Do you, Mr. Jones?  -  [bob dylan]

#7: 3-Feb-2009, 11:27 AM

Foundation

rthrash
Posts: 11,575

WWW
Also be careful about making suggestions, unless you're ready to step up an volunteer. Wink
MODx is a content management framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.