jzvanenk Posted April 18, 2013 Share Posted April 18, 2013 This is my 3rd day trying PW, and I am new to CMS/CMF as well. I followed the tutorials for simple walk through and the basic web site happily. (Thank you heros!) But when I started trying more stuff, such as building an article index page, I struggled more. I realize what I am confused about was really something quite basic, such as where are the snippets of php code go beside on templates? Can they go on a page as the value of body field for example? I tried it without success. I would appreciateit if someone can point me to a place where I can find answers to more basic questions for novice, and perhaps some introductory concepts for the architechture? Thanks in advance! Link to comment Share on other sites More sharing options...
3fingers Posted April 18, 2013 Share Posted April 18, 2013 I jzvanenk, Did you read the API Documentation ? You can find all the answers you need there. Sorry if I'm short on answer, but Ryan had explained every basic concepts there, way better than what I could do myself here now Link to comment Share on other sites More sharing options...
jzvanenk Posted April 18, 2013 Author Share Posted April 18, 2013 Thank you 3fingers! This is a very helpful pointer. I know there is a lot of great stuff on the site, just need to get a sense where to find it. Link to comment Share on other sites More sharing options...
diogo Posted April 18, 2013 Share Posted April 18, 2013 Welcome jzvanenk! Answering directly to your question. The snippets don't go inside the fields, they go directly on the template files. The code you have on the template files is PHP, just like the snippets yo are talking about. So, when you have this on the planets tutorial: <html> <head> <title><?php echo $page->title; ?></title> </head> <body> <h1><?php echo $page->title; ?></h1> <h2>Type: <?php echo $page->planet_type; ?>, Age: <?php echo $page->planet_age; ?> years</h2> <p><?php echo $page->planet_summary; ?></p> </body> </html> You can also have this: <html> <head> <title><?php echo $page->title; ?></title> </head> <body> <header> <ul id="all-planets"> <?php // list all planets and link to their pages foreach($pages->get("/planets/")->children as $planet){ echo "<li><a href='{$planet->url}'>{$planet->title}</a></li>"; } ?> </ul> </header> <h1><?php echo $page->title; ?></h1> <h2>Type: <?php echo $page->planet_type; ?>, Age: <?php echo $page->planet_age; ?> years</h2> <p><?php echo $page->planet_summary; ?></p> </body> </html> edit: that is the same as this (entering and leaving php to write html): <html> <head> <title><?php echo $page->title; ?></title> </head> <body> <header> <ul id="all-planets"> <?php foreach($pages->get("/planets/")->children as $planet): ?> <li> <a href="<?php echo $planet->url; ?>"><?php echo $planet->title; ?></a> </li> <?php endforeach; ?> </ul> </header> <h1><?php echo $page->title; ?></h1> <h2>Type: <?php echo $page->planet_type; ?>, Age: <?php echo $page->planet_age; ?> years</h2> <p><?php echo $page->planet_summary; ?></p> </body> </html> 3 Link to comment Share on other sites More sharing options...
jzvanenk Posted April 19, 2013 Author Share Posted April 19, 2013 diogo: Just the answer I am looking for. Kudos to you! I hope other newbies benefits as well. Link to comment Share on other sites More sharing options...
k07n Posted April 19, 2013 Share Posted April 19, 2013 edit: that is the same as this (entering and leaving php to write html): Hi, diogo. Which method is better to use? "Echoing" or "html outside php"? Link to comment Share on other sites More sharing options...
3fingers Posted April 19, 2013 Share Posted April 19, 2013 @k07n: I'ts just a matter of tastes there. I honestly prefer to write all the php first (In this particular case the foreach loop) and then echoing the results inside html tags. Doing so I avoid to forget the closing php tags each time, and for me it's more readable also. 2 Link to comment Share on other sites More sharing options...
diogo Posted April 19, 2013 Share Posted April 19, 2013 Most of the examples that you will find here on the forum use the first method, and thats's also the one I tend to use, but the second method has it's merits. If you worry about how the source code looks (before firebug and chrome developer tools it was important for debugging) the second method respects the indentation and keeps the html tidy, although you can also achieve that inside a php with \t and \n (tab and newline characters): echo "\t\t\t<li><a href='{$planet->url}'>{$planet->title}</a></li>\n"; 1 Link to comment Share on other sites More sharing options...
pwired Posted April 19, 2013 Share Posted April 19, 2013 Great thread with good explanations working for me also. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now