Jump to content

I need help with link pages with processwire


AmadeuAntunes
 Share

Recommended Posts

Hi,

First, try to follow that tutorial : Simple Website Tutorials to see step by step the basic PW mechanic.

Then, take your time to get around the rest of The Docs

Meanwhile, I'll try a "short version" of that, with the content circulation from creation to the browser:

1> First you create a *CustomField* to store some content, who will be at the end shown into the browser. And giving to that field some unique name.

2> Then, your "Page" is more of a box where you store a set of specific CustomFields. That box is associated with one unique *Template*

3> The *Template* is simply a .php file stored into /site/templates/

4> -Now the magic happen, basically as follow

Assuming that you have a TextField, with the name "myContent", that you can fill in the backend on a Page (box) named "Test", and tied surprisingly to the test.php template ...

1. To output the Content (aka our field) on the Test Page, just open test.php template and in the chosen spot type:

<?php echo $page->myContent; ?> // Classic form...
<?= $page->myContent; ?> // or short form.

2. Basically again, if you need that content on another template/page than Test, you can pass from the global variable, and find the right "fields box" by the template name it use. So, on any other template, you can access the content of the "myContent" field like so:

<?php echo $pages->find("template=test")->myContent; ?> // Classic form...
<?= $pages->find("template=test")->myContent; ?> // or short form.

PS: There are many other ways and forms to target and display the content, take some minutes with the Selectors ;)

- Don't know if I really understood your question ^^, but hope it helps a little.

  • Like 1
Link to comment
Share on other sites

2. Basically again, if you need that content on another template/page than Test, you can pass from the global variable, and find the right "fields box" by the template name it use. So, on any other template, you can access the content of the "myContent" field like so:
<?php echo $pages->find("template=test")->myContent; ?> // Classic form...
<?= $pages->find("template=test")->myContent; ?> // or short form.

<?php echo $pages->get("template=test")->myContent; ?>             // use get
<?php echo $pages->find("template=test")->first()->myContent; ?>   // or use first after find

@Andrei: I think it is a typo, but an incorrect example may be confusing for beginners.

$pages->find($selector) always returns an array, where you further need to select one item out, with e.g. ->first(), ->last() or ->eq(#).

If you know that there is only one page that will match your selector, (or you only need to get the first match), you can use $pages->get($selector), which will return only a single item.

  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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