Jump to content

Recommended Posts

Posted

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 appreciate
it 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!



 

Posted

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 :)

Posted

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. 

Posted

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>
 
  • Like 3
Posted

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"?

Posted

@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.

  • Like 2
Posted

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";
  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...