Mark Posted March 22, 2013 Share Posted March 22, 2013 Hi, I am going through the tutorials found on: http://processwire.com/api/templates/ I would like to output my body field but the code found on the templates info page is not working for me! <div id='body'> <?=$page->body?> </div> This however is! The code below was found in the templates folder (frontpage.php) echo "<p>" . $page->body . "</p>"; Are the two snippets of code supposed to output the body to the page in the same way (ignore the styling). I'm sorry for the silly question......I'm new! Link to comment Share on other sites More sharing options...
MatthewSchenker Posted March 22, 2013 Share Posted March 22, 2013 Greetings Mark, Welcome to ProcessWire! That looks like it should work, but a couple of things that sometimes don't work: 1. Short tags. Instead of this: <?=$page->body?> Try this: <?php echo $page->body; ?> 2. Double quotes for referencing the body ID, like this: <div id="body"> These are not really a ProcessWire issues, but general HTML things. Try it and let us know! Thanks, Matthew Link to comment Share on other sites More sharing options...
DaveP Posted March 22, 2013 Share Posted March 22, 2013 (edited) It's probably that your php settings don't include short_open_tag, so <?=$page->body?> won't work. <?php echo $page->body; ?> is exactly equivalent, and if (as is the default) your body field is coming from a tinymce input, it will already include <p> and </p>, so you don't really need to output them again. <edit>Damn, Matthew beat me to it.</edit> Edited March 22, 2013 by DaveP Link to comment Share on other sites More sharing options...
Mark Posted March 22, 2013 Author Share Posted March 22, 2013 Hi Matthew and Dave, Thanks very much for your fast reply....Matthew was quicker by 3 minutes I have attached the full php code to hopefully show what I'm doing wrong. <?php include("./TUT_header.inc"); echo "<h2>" . $page->title . "</h2>"; // Working! <?php echo $page->body; ?> // Not working! include("./TUT_footer.inc"); without using tinymce what would be the best way to style the static 'Direction' red and the dynamic 'direction' blue using your method? Thanks, Mark echo "<p>Direction: " . $page->direction . "</p>"; // Working! Link to comment Share on other sites More sharing options...
Mark Posted March 22, 2013 Author Share Posted March 22, 2013 echo $page->body; Everything is starting to become a little clearer. It looks like when I try and make a reference to a .inc file it's throwing everything off. Link to comment Share on other sites More sharing options...
totoff Posted March 22, 2013 Share Posted March 22, 2013 <?php echo $page->body; ?> is nested within another php tag. remove it from there. and it should be <?php echo "$page->body"; ?> http://www.php.net/manual/en/function.echo.php Link to comment Share on other sites More sharing options...
Luis Posted March 22, 2013 Share Posted March 22, 2013 Chris on this way you advise php to Output a string which will be $page->Body in HTML and not the referenced data Forget what i Said .... " and ' Shame on me Link to comment Share on other sites More sharing options...
totoff Posted March 22, 2013 Share Posted March 22, 2013 echo "<p class='alert'>Direction: <span class='noalert'>" . $page->direction . "</span></p>"; // Working! .alert {color: red;} .noalert {color:blue;} 1 Link to comment Share on other sites More sharing options...
diogo Posted March 22, 2013 Share Posted March 22, 2013 Mark, I think the source of your confusion here is that you still don't understand how PHP works. Unlike other programming languages, PHP can integrate with HTML in two ways: by integrating it, or by being integrated inside it (ok, strange sentence, but I hope it delivers the point). these two do the same thing: <?php echo "<h2>" . $page->title . "</h2>"; ?> <h2><?php echo $page->title; ?><h2> The difference is that, in the first code you are telling PHP to output all the content, while in the second example, you are using it to output only the dynamic content between static content. The important thing to understand (and this was your mistake), is that you start the file outside PHP, and then you can enter it with "<?php" and leave it with "?>". You can never open a PHP tag, when you are already inside another, like here: <?php <-- we opened PHP include("./TUT_header.inc"); echo "<h2>" . $page->title . "</h2>"; <?php echo $page->body; ?> <-- and we opened it again without having closed it before You should read an introduction to PHP to learn all these concepts, and you will see that PW will be much easier then. 4 Link to comment Share on other sites More sharing options...
Mark Posted March 22, 2013 Author Share Posted March 22, 2013 I'm amazed by the PW community. Thank you so much everyone, I really appreciate your help. Diogo, yes, it's the PHP that was confusing me. I will have to get back to basics and understand the rules of PHP. Thanks for your clear explanation. Totoff, thanks for help with the code plus adding the style. 1 Link to comment Share on other sites More sharing options...
onjegolders Posted March 22, 2013 Share Posted March 22, 2013 Stick at it Mark, a lot of us here were complete PHP beginners when we started. It won't take more than a couple of online video tutorials or reading some chapters in a book to get the hang of the basics Link to comment Share on other sites More sharing options...
Mark Posted March 22, 2013 Author Share Posted March 22, 2013 Hi onjegolders, Thanks for the encouragement. At least I can see instant mistakes with PW. Drupal made me clear the cache before I was allowed to see them! 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