yellowled Posted April 2, 2012 Share Posted April 2, 2012 Hi everyone. So far, I love PW. Now, before I start using it in more than some get-to-know-it projects on localhost, I'd like to make sure I understand in properly. So everything is a page, right? Not only every piece or group of text or data I want to display in an actual page, but also stuff I might want to pull into a page is supposed to be put in a separate page – like news items, blog articles, events, staff members etc. Or should certain types of data actually be stored in a different kind of way (XML or JSON comes to mind) to make it easier or more performant to process? Let's say I have a page which contains some fields, but it's not supposed to be displayed as an actual frontend page. It only exists to store those fields and will be referenced in an actual page, mostlikely its parent. My "natural" way of approaching this would be to assign some kind of "snippet" template to the page containing the content, i.e. the markup which it should have in the parent page. But that doesn't seem to be the way it's supposed to be handled in PW, at least I haven't found a way to do "insert $page here with the markup assigned to it in its template". This does make sense since it gives me more flexibility to emit the same data with different markup in different context. However, in some cases where I don't need that, my "natural approach might be easier. Is there a way to do that? Hope this makes sense. Link to comment Share on other sites More sharing options...
Soma Posted April 2, 2012 Share Posted April 2, 2012 welcome to the forums yellowled. yes everything is threated as pages. I don't think certain types stored as xml or json will not make it more performant than mysql, rather opposite. If a page exists only to store informations that the can be pulled form anywhere is a good way. It doesn't even need to have a ".php" template attached if that's page never going to be viewed anyway. You can of course have data as pages that will get displayed through other pages. One way to display it is using code in the page template that will render the data, so in the foreach you have something like a markup generating code. FOr example often used is something like this. if(count($page->children('template=member'))){ foreach($page->children('template=member') as $m){ echo "<div class='box'>"; echo "<div class='image'>"; echo "<img src='{$m->image->size(200,0)->url}'/>"; echo "</div>"; echo "<div class='text'>"; echo "<h2>{$m->title}</h2>"; echo "<h3>{$m->member_function}</h3>"; echo $m->member_descr; echo "</div>"; echo "</div>"; } } Or other ways of doing it, as you like. Another possibility would be to have a member.php that will contain the markup and then can be rendered using the $page->render(); in the member.php: <div class='box'> <div class='image'> <img src='<?php echo $page->image->size(200,0)->url ?>'/> </div> <div class='text'> <h2><?php echo $page->title ?></h2> <h3><?php echo $page->member_function ?></h3> <?php echo $page->member_descr ?> </div> </div> then the previous would be like this: if(count($page->children('template=member'))){ foreach($page->children('template=member') as $m){ $m->render(); } } There's not "right" way, just what you like most and would make sense in your situation. There many many ways to build it. EDIT: corrected some code... Link to comment Share on other sites More sharing options...
yellowled Posted April 2, 2012 Author Share Posted April 2, 2012 You can of course have data as pages that will get displayed through other pages. One way to display it is using code in the page template that will render the data, so in the foreach you have something like a markup generating code. FOr example often used is something like this. I was aware of that – but that way, the template code is added to the parent's template file, which is fine and very flexible, but kind of confusing to me at times since I've never used a CMS before which does it that way. Another possibility would be to have a member.php that will contain the markup and then can be rendered using the $page->render(); Ah, so that's what $page->render(); is for – it renders (in baby developer's talk – I'm not a skilled PHP coder) a page according to the template assigned to said templatepage, but maybe in a different context? That's smart. As I tried to say before – it all makes sense and gives users great flexibility, it's just a bit confusing sometimes if you're used to other systems. Link to comment Share on other sites More sharing options...
MadeMyDay Posted April 2, 2012 Share Posted April 2, 2012 Since Yellowled also knows MODX very well (hi btw ) I just want to give my two cents to the topic with some MODX comparisons. In MODX you usually have snippets which do the logic an chunks which do the presentation. In PW you either define the logic yourself (often foreach over a set of pages) or have modules which do that for you. For the markup there seem to be several approaches. Soma showed two of them, echoing the markup right in the template and rendering external templates. While I don't like the "echo"-approach (it just looks ugly) the render() afaik can only render page templates. So I tried something different and to my surprise (well, not really) it works well. You just can organize yourself like in MODX. I even called my folder for mini templates "chunks". For example in my current project (my portfolio) I have a list of client work stored in a folder with an own template (for assigning the fields). This reference template has no own .php file, because they are not shown on a single page (it is a one pager). I have a overview list with some thumbs and then more details on every item later: <section id="references"> <article class="overview ref active"> <?php $refs = $pages->get("/referenzen/")->children; $count = 0; foreach($refs as $ref) include("./tpl/overview.inc"); ?> </article> <?php $count = 0; foreach($refs as $ref) include("./tpl/ref.inc"); ?> So basically I just loop over my references and "oldschool" include my chunk which looks like this: <? if($count != 0){ ?> <div class="screenOverview imgContainer ref<?= $count ?>"> <picture class="c" data-nr="<?= $count ?>" alt="Screenshot von <?= $ref->title ?>"> <!-- <source src="<?= $ref->image_c->width(384)->url ?>"> --> <source src="<?= $ref->image_c->width(384)->url ?>"> <!-- <source src="<?= $ref->image_c->width(550)->url ?>" media="(min-width: 1000px)"> --> <source src="<?= $ref->image_c->width(550)->url ?>" media="(min-width: 1000px)"> <!-- <source src="<?= $ref->image_c->width(650)->url ?>" media="(min-width: 1280px)"> --> <source src="<?= $ref->image_c->width(650)->url ?>" media="(min-width: 1280px)"> <!-- Fallback content for non-JS browsers. Same src as the initial source element. --> <noscript><img src="<?= $ref->image_c->width(550)->url ?>" alt="<?= $ref->title ?>"></noscript> </picture> </div> <? } $count++ ?> (using the picture polyfill in this case). So this means: you can just include any file and stay better organized. The variables are assigned and you even can reuse these "chunks". In the second loop I iterate again over the references and build something different (with description and such) with a different "chunk". Works pretty well and lets you keep well organized. 1 Link to comment Share on other sites More sharing options...
diogo Posted April 2, 2012 Share Posted April 2, 2012 "pages" it's a convenient way of calling well, pages, since they are associated with URLs. But it's best if you forget the word "pages" when developing because it leads you to think of visible website pages, when they really are pieces of content that you can use the ways it suits you better. Link to comment Share on other sites More sharing options...
yellowled Posted April 2, 2012 Author Share Posted April 2, 2012 Personally, I think I prefer to use PW's API as far as possible (which seems to be pretty far). The reason is simple: As soon as I'd need extra PHP code beyond the very basic stuff needed with PW's API, I'd be lost. For me, PW's API really does work like jQuery in the ssense that it gives me an easy-to-use "layer" and spares me having to really use the language "below". Also, I think it's confusing to still think in the terminology of any other CMS. I really don't know MODx that well, so I'm perfectly happy to "think in PW terms". 1 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