Jump to content

Beginner Template - _foot.php - generell fields possible?


tomtomt
 Share

Recommended Posts

Hi there - yes i am new and sorry, i hope my english will be good enough,

I am working and learning with the "Site-Beginner Profile.

I have these two _head.php and _foot.php files.

I would like to have something like the fields in templates, but in the _foot.php.

I have created 3 fields, footer1 footer2 footer3, but i have to put them into all of my page templates - to show them on all pages.

Is there an easier way? Something like "global fields, that i can put once into the _foot.php, so that i have only once to fill them with content over the admin backend?

Thanks folks

Tom.

Link to comment
Share on other sites

Hi monchu,

thanks very much. But maybe i have some wrong thoughts.

OK, i did as you say. My first problem was, my footer.php was not shows in the admin panel, because it couldnt assoziate the template with my file in a subdirectory.

So i put my footer,php into the normal template directory.

Found it in the backend - i filled it with fields.

After that i put 

<?php include ("./footer.php"); ?>

into my _foot.php.

But its not shown on the homepage. In my mainmenu i have now the item "footer". When i click on it, it shows me the content of my footer fields, but without any styles.

Thanks

Link to comment
Share on other sites

Sounds to me like there's a bit of a misunderstanding here. First of all, fields are connected to templates (home, basic-page, etc.) and field values are applicable to pages using that template, so technically there's no such thing as a field with the same global value everywhere. You can solve this in a different way, though.

Taking a step back, what you originally asked for was ...

Quote

I have created 3 fields, footer1 footer2 footer3, but i have to put them into all of my page templates - to show them on all pages.

Is there an easier way? Something like "global fields, that i can put once into the _foot.php, so that i have only once to fill them with content over the admin backend?

The easiest way to achieve this would be adding those fields to an existing template – such as "home" – and filling in the values for a page using that template – in this case your home page. Then you can do something along these lines in your _foot.php file:

<?php echo $pages->get(1)->footer1; ?>

In other words you can fetch a specific page ("1" in this case means the page with ID 1, i.e. your home page) and then output the value of the field ("footer1") from that page.

From what you've written above, it sounds like you might've created a new template called "footer", added fields to it, and then perhaps created a new page using this template too. Sound familiar? If so, you can also use that page as well (instead of, say, your home page) to store your footer values: in your _foot.php you can get that page and output the value from it with <?php echo $pages->get('/footer/')->footer1 ?>.

Does this make sense to you? :)

  • Like 6
Link to comment
Share on other sites

Hi. Welcome to the ProcessWire forums. :)

Have you already read on the concept of page/templates/fields? If not, this is a must read article to fully understand how ProcessWire works:

ProcessWire CMS – A Beginner’s Guide

----

Now to your question:

1 hour ago, tomtomt said:

I have created 3 fields, footer1 footer2 footer3, but i have to put them into all of my page templates - to show them on all pages.

This i not true. You only need to assign these fields into one template, and then create a page using that template. For instance, if you assign these fields to the home page, you'll be able to access them everywhere. Once you edit the home page assign values to these fields:

Home
--------
footer1 [ left foot    ]
footer2 [ right foot   ]
footer3 [ middle foot? ]

In your foot.php you could have something like:

echo $pages->get('/')->footer1 . PHP_EOL;
echo $pages->get('/')->footer2 . PHP_EOL;

// or

$home = $pages->get('/');
echo $home->footer1 . PHP_EOL;
echo $home->footer3 . PHP_EOL;

// output:
// left foot
// right foot
// left foot
// middle foot?

I suggest you make an effort to fully grasp the page/templates/field concept, because after that everything in ProcessWire come really easy. :)

  • Like 1
Link to comment
Share on other sites

Hello teppo,

fantastic: <?php echo $pages->get('/footer/')->footer1 ?> - this was exactly what i want. It works. Now i have made my footer page hidden in lists an search; it is now not shown in the mainmenu, but shown in my footer on every page.

Thanks very much. I think i have to train my english a little bit ;)

Tom.

  • Like 2
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...