Ade Posted July 8 Share Posted July 8 Although I've read almost every page in the documentation — I even understood some of it — I had to wing it to get this far. By guesswork, I saved some blank template files for content types, made the corresponding templates, and created some simple fields to fill in one of those templates. Summary, body, image, tags, basically. (By the way: the warning message shown when trying to make a new template is not very informative!) Some example text in the body field and <?=page()->body?> added to an otherwise empty template (keeping it simple) and one very small step was made. So what are the next steps required to print the entire page content? I am comfortable with hand written HTML, but I have some questions about how build a complete template system. Should each template be a complete HTML doc or just a segment — or does it not really matter? If it should be segmented, how is it divided up into other templates and how are those templates loaded? How is an HTML region which contains several content elements — such as URLs and titles in a typical <nav> and <ul> structure — populated with those elements by PHP? Link to comment Share on other sites More sharing options...
elabx Posted July 9 Share Posted July 9 Hi @Ade! I think your next step is elaborating on the output strategy! Have you taken a look at this section? https://processwire.com/docs/front-end/output/ I think it should answer all of your questions. An also popular and more complete/opinionated output solution is RockFrontend. 1 Link to comment Share on other sites More sharing options...
Krlos Posted July 9 Share Posted July 9 I recommend checking out PW Tuts pwtuts.com. There, you can find basic concepts that will help you understand the fundamentals and allow you to create quite advanced websites. 3 Link to comment Share on other sites More sharing options...
Ade Posted July 9 Author Share Posted July 9 (edited) As I say, I've looked at almost every page of the docs: I've read the output pages more than once, but they don't make much sense and they lack real and usable examples. Once it starts using multiline PHP, I struggle to read and comprehend the more complex code. PW Tuts looks useful. Thank you. Edited July 9 by Ade Link to comment Share on other sites More sharing options...
da² Posted July 9 Share Posted July 9 4 hours ago, Ade said: Once it starts using multiline PHP, I struggle to read and comprehend the more complex code. So the next step is probably to learn PHP more. ? 1 1 Link to comment Share on other sites More sharing options...
Ade Posted July 9 Author Share Posted July 9 I do not think that you understand why I may struggle to read it. I'm disappointed to receive an unconstructive comment like that when I am asking for assistance. But message received: "don't bother us". Link to comment Share on other sites More sharing options...
Gideon So Posted July 9 Share Posted July 9 Hi @Ade Welcome to the Processwire world. I started with the following tutorial. It help me a lot and I was no PHP developer at all at that time Gideon 2 Link to comment Share on other sites More sharing options...
Tiberium Posted July 9 Share Posted July 9 28 minutes ago, Ade said: I do not think that you understand why I may struggle to read it. I'm disappointed to receive an unconstructive comment like that when I am asking for assistance. But message received: "don't bother us". The comment is valid. What you struggle with, is a basic using of the PHP language, not ProcessWire itself. That is also not a bad thing, I personally started learning PHP with ProcessWire. A PHP Tutorial that explains the basic things with examples close to easy HTML together can be a starting point. Or looking at the Code of the basic profile as you did and then research the things who are unclear with the PHP documentation. Gideons link is also a good starting point. Your last sentence is also not productive. There was no bad intention in the post before. This community here is an example of the opposite. 3 Link to comment Share on other sites More sharing options...
BrendonKoz Posted July 9 Share Posted July 9 On 7/8/2024 at 4:24 PM, Ade said: I am comfortable with hand written HTML, but I have some questions about how build a complete template system. Should each template be a complete HTML doc or just a segment — or does it not really matter? If it should be segmented, how is it divided up into other templates and how are those templates loaded? How is an HTML region which contains several content elements — such as URLs and titles in a typical <nav> and <ul> structure — populated with those elements by PHP? What @da² mentioned above is kind of what I was thinking too, so I don't think he meant harm by it. You pointed out your comfort with HTML and confusion on multiline PHP, so the points are there for us to create an assumption. Apologies if it's wrong! ProcessWire is a content management framework, so it does require some level of understanding of development on both a higher and lower level, or at least the ability to read through code - it took me until just this year to realize that a lot of the documentation are actually in comments in the code, or in Markdown files that developers provide with their modules. I felt (partially) silly for only ever trying to look at written documentation. Like you, I love examples too; much of which exists in the forums, honestly. Anyhow, that being said, I may not be the best person to provide a response, but I do want to try to help you out here. The problem with these questions though are that each and every one can begin the response of the answer with: "It depends." Typically each template is not an entire HTML document, as you'll have one (or two) main layout file(s) that then get merged with your template in one way or another. This would depend on your output strategy as linked above. Since you're just starting out, it might make the most sense to give Direct output a try so that you can start to understand how ProcessWire works. I'm assuming though, since you read through the documentation, you'd also read the last part on the direct output page that mentions its drawbacks (I assume this based on question #3 above). Part of the solution to this, with direct output, is understanding the ProcessWire API. You can retrieve any "page" or page content within the system from pretty much anywhere by using the API. It's extremely powerful. Depending on your needs, you'd likely need to do some manipulation on the returned data prior to rendering it as HTML, but the point is that it's accessible to retrieve. This will depend on your own imagination on how you want to build your site profile out. If you've got some time, you might want to setup some test ProcessWire sites, and install some pre-made site profiles that you can examine and look through to understand how each developer decided how to set things up. There's no real right way to do things, and a lot of it will depend on the project's needs and requirements. Sure there are better ways to do things, but a lot of us don't figure that out until after we've made the not-better solution first. ? As a partial example to this question though - let's say you have a very simple blog. You have two system templates (thus far) - one that lists all blog posts, and one that views a specific blog entry (post). You have four template files: (1)header.php, (2)footer.php, (3)blog.php, (4)post.php. Posts are children of Blog, and Blog is the parent of Posts. (You could consider "Blog" as the homepage I guess in this very simple example.) Your header and footer contain your site's template, split up as expected. The blog.php and post.php files include the header and footer. (We won't worry about navigation at this point, this is a simple example.) The Blog template file uses the API to find and retrieve all Posts, or its children. It then outputs the title, as a hyperlink, to the blog post itself. (This could be adjusted to make sure entries are chronological - normally it would likely retrieve them that way, but depending on how you develop the system that might not always be the case.) if ($page->hasChildren()) { echo "<ul>"; foreach($page->children() as $post) { echo "<li><a href='$post->url'>$post->title</a></li>"; } echo "</ul>"; } The Post template file wouldn't need to know about any other pages; its purpose is to display the content contained for its own page. Surely it can though - it could display next, previous, or related posts. Again: The API can help with those scenarios (related would likely use tags or categorization of some sort). So when someone visits the post, as linked to from the Blog, the post.php file would use fairly simple PHP to output its own content. Let's assume the post system template has 3 fields: Title, Summary, and Body. The Blog excerpt above only shows how to loop through its child pages to output links, the Post excerpt below will have a bit more HTML just to hopefully provide more context. <h1><?= page()->title ?></h1> <div class="blog-summary"><?= page()->summary ?></div> <div class="blog-story"><?= page()->body ?></div> Remember, content above and below are handled by the header.php and footer.php files that are included in the post.php file, in this simple example. I could've added it above, but, well...oops. ? Are you asking about an HTML region, or a ProcessWire markup region? Verbiage with ProcessWire can get a little confusing, so I just want to be sure. Assuming you're just asking about some random area of HTML content on a page getting dynamically loaded from other areas of the system - you'd use the PW API. So let's say you want to get the title of the current page from the header.php file, which is a template file, not a (PW) system "template", so it doesn't have its own PW "page" fields, it's just a file. But you can still use the PW API to query all pages, get a resultset, and then process that data to output what you want. You've seen the children() method above. You can also use the pages()->get() method to retrieve the site's root homepage, which can be referred to either as "/", or 1...so that would be $homepage = pages()->get('/'); or $homepage = pages()->get(1);. From there, you can use the return value in $homepage and then find its children. You now have a first-level for your navigation links, if you decide to setup your navigation based on the tree structure of your site (you don't have to). I can't say whether this is any more helpful or not than other forum responses, or examples in the docs. Generalized questions are really hard to answer simply because there are so many ways to come up with a solution and a lot of it depends on many various factors. 6 Link to comment Share on other sites More sharing options...
da² Posted July 9 Share Posted July 9 1 hour ago, Ade said: I do not think that you understand why I may struggle to read it. I'm disappointed to receive an unconstructive comment like that when I am asking for assistance. But message received: "don't bother us". Why is it not constructive? Sorry that you interpret my comment that way. I've also read the output strategies tutorials and explanations were clear to me, so if you think "they don't make much sense" and you "struggle to read and comprehend the more complex code" I think you lack some PHP background. Maybe I'm wrong, it seems you are saying the problem is not about PHP knownledge, maybe you could explain so we can be more precise in the help we give to you. 2 Link to comment Share on other sites More sharing options...
cwsoft Posted July 9 Share Posted July 9 (edited) The PW forum is a place of the most friendly and helpful people I ever interacted with in web based CMS/CMF forums so far. What I learned from other forums is, that showing as much code you already tried (e.g. I put this code xxx into /site/templates/myfile.php) and asking a single question closely related to your code example (e.g. I expected to get x, but instead I see y) would help all involved people to better grasp each others standpoint and to provide better replies to specific questions. Cheers cwsoft Edited July 9 by cwsoft 5 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