Jump to content

Recommended Posts

I've seen references to the page title, but where in ProcessWire can I set the site title, and how do I include it in my templates?

My total experience with ProcessWire is about two hours, but it looks very promising. I develop primarily in WordPress, but the "post" structure has proved itself to be limiting.

Link to post
Share on other sites

Hi lance, welcome.

PW is very flexible and has no "Site" title as it's mostly something you set/code in your template. However you could use any field or page title field as the site name from any page you like. So maybe use the root node "home" on the top of the tree to define a site title for your website.

To for example simply output the title from the root page use

echo $pages->get("/")->title;

Or if you want you could create a simple textfield ie. "site_title" and add that to the "home" template in PW. Then you simply change the above to

echo $pages->get("/")->site_title;

Another possible route is to use config file to add a title

in /site/config.php

$config->site_title = "MyHomepage";

then to you can access it from any php template like

echo $config->site_title;
  • Like 4
Link to post
Share on other sites

There ain't such a thing by default. You can do template "settings", with fields like "Site title", "Copyright text" etc... and create one page with that template which keeps your "site settings" if you need to. But usually it is just better to hard code stuff like that to your template file. Site title is thing that rarely changes and if you have build your templates well, you need to change it from one file only.

So in default site profile you would edit head.inc file and add your site title to <title><?php echo $page->title;?> - Site title</title>

And welcome to the forums Lance!

EDIT: This forum sometimes let you know about other replies before you, sometimes it just posts it :/

Link to post
Share on other sites

Hi Lance. I actually don’t think there is one as you’d expect it from CMS you may be used to.

I usually use the home page’s title as the site’s name and create a var $home at the top of the header include like this:

if($page->path == "/") {
 $home = $page;
} else {
 $home = $pages->get("/");

and use it e.g. in <title></title> like this:

<title><?php echo $home->title.($home->id != $page->id)?" – ".$page->title:""; ?></title>

Sometimes I create a custom text inputfield for the site’s name and add it to the home template, so I can take it from there like this:

// or if used like above

When I use the $home solution, I often use the home template to store general information on the site. But you also could create a hidden page as an info container for this.

Link to post
Share on other sites

Lance I'm not sure specifically what a site title is, but guessing you just mean some common string of text that's repeated on every page? If so, I would probably add a text field to your homepage template and call it 'site_title' or whatever you want. Then have your main template (or head.inc) output that text wherever you want it to appear. For instance:

$site_title = $pages->get('/')->site_title;
echo "<a id='logo' href='{$config->urls->root}'>$site_title</a>";


Edit: holy smokes, there were no replies when I started writing. I hit reply and now there's 3. :) You guys are fast.

Link to post
Share on other sites

So many different answers for such a simple question :D This is how flexible PW is!

and I will add another one ;)

If you would like to have the kind of "settings" page that CMSs like Wordpress have, you can create a page named "site_settings" or "preferences" or "watheveryouwant", and throw there fields like "site_title", "background_color", "content_width", etc... and call them from templates like this:

$settings = $pages->get('name=site_settings');
$title	   = $settings->site_title;
$background  = $settings->background_color;
$width	   = $settings->content_width;

EDIT: I created variable $settings for readability

  • Like 1
Link to post
Share on other sites

Wow, five responses to my question! Really impressive!

Including a variable in a config file makes sense. But from the point of view of my clients, many will question why they can't modify the site title directly in the CMS. Giving them the ability to change it and other variables, even if they won't, is really important.

Thanks for the welcome to the forum!

Link to post
Share on other sites
  • 3 weeks later...

I think I like diogo's route and have got it working after a bit of a steep learning curve (boy am I new at this).

But I don't understand how to most efficiently use the results.

Right now I have this in a template, just to prove it's all working (it's a bit verbose for now while I am still so unsure):

$settings    = $pages->get('name=site-settings');
$pref_site_name_simple = $settings->pref_site_name_simple;
$pref_site_strapline = $settings->pref_site_strapline;
$pref_site_name_precise = $settings->pref_site_name_precise;
echo $pref_site_name_simple;
echo $pref_site_strapline;
echo $pref_site_name_precise;

Q1. If after learning how to do this I wanted to create a new template and, say, just publish the $pref_site_name_simple, would I have to use this much code?:

$settings    = $pages->get('name=site-settings');
$pref_site_name_simple = $settings->pref_site_name_simple;
echo $pref_site_name_simple;

Q2. If I created 10 templates that will need to use this data, is there a DRY (don't repeat yourself) way to include it so that if for example I suddenly decided I wanted the third line to read:

echo "This site is: "; $pref_site_name_simple;

I wouldn't have to go and edit the code in 10 places? I suppose I could use .inc file but that feels very 'low tech' and feels like I am straying far from the optimum way of using PW in this example.

Sorry these are such lame questions, I'm just keen to not begin on the wrong foot and use PW inefficiently.

Thanks a lot for any comments, cheers, -Alan

Link to post
Share on other sites

Q1. If after learning how to do this I wanted to create a new template and, say, just publish the $pref_site_name_simple, would I have to use this much code?:

Your code looks longer mainly because your variables and field names are also very long. The same code looks shorter like this:

$settings = $pages->get(123);
$sname = $settings->simple_name;
echo $sname;
Q2. If I created 10 templates that will need to use this data, is there a DRY (don't repeat yourself) way to include it so that if for example I suddenly decided I wanted the third line to read:

You can put all your variables on "settings.inc" file, for instance, and include it on the "head.inc" file, or whichever file that you know will be included by all the templates.

EDIT: changed get('name=site-settings') to get(123) to make it even shorter ;)

Link to post
Share on other sites


If all you want to do is echo the contents of the field 'pref_site_name_simple' belonging to the site-settings page probably this:

echo $pages->get("/site-settings/")->pref_site_name_simple // or "name=site-settings" if you expect the page to move in levels

or if you want to make a variable for reuse:

$psns = $pages->get("/site-settings/")->pref_site_name_simple

Remember the PW api allows for chaining, and all fields are at your fingertips regardless from what template you are working.


There's nothing low-tech about an inc file. Instead it seems ideal to store stuff like you mentioned.

Link to post
Share on other sites

Thanks SiNNuT.

Remember the PW api allows for chaining, and all fields are at your fingertips regardless from what template you are working.

I had totally missed that (boy am I new to this) but from chaining in jQuery I see what you mean here and it's music to my eyes, thanks for the advice.

Link to post
Share on other sites
  • 2 years later...

i created a page with some of those global settings, such as: a collection of images for the banner's slideshow, the sit'e logo, its name, the footer, etc. and to make it more dynamic, i merge it with the title of the page, like so:

in the beginning of the file, before any html:

$pg_settings = $pages -> get('name=settings');

on the title:

<title><?=$pg_settings->title ." / ". $page -> title; ?></title>

and (for completion) on the footer:

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By RyanJ
      I have quite the pickle. 
      The admin no matter where I am at in it, times out constantly. I either get a 504 gateway or and execution timeout. I am banging my head why its across the board. The frontend of the site works great.
      The site does have a lot of pages, 164,889 to be exact.  Most of that is due to image pages created by media manager and having repeater matrix installed which is used on most of the pages. For some reason, if I can manage  click the "Clear file compiler" without it timing out, the site perks back up and I can access the admin again and it is quite speedy. However if I walk away leaving the browser sitting for about an hour and come back, I have to start the process all over again.
      The site has 52 various fields. Not every field is assigned to every template. a lot of the fields are used by the matrix to create a page builder.
      I can't accept that PW can't handle such. I have other sites that run triple the amount of pages, but don't rely on the matrix to build the layout.
      I have disabled any custom module that I thought could possibly cause an issue. I have overwrote every module and the wire core thinking something may have got corrupted. I guess my next step is starting with a fresh install, but I thought I would reach out to see if I am missing something. 
      Some background on pages:
      All the pages are imported using the command line which bootstraps PW and uses the api. This is a dev site, so I blow away the pages if I need to reimport them, until I get it correct.
      PW Version 3.0.172, PHP 7.3, Innodb 5.7.27-30.
      I appreciate any suggestions or thoughts. 



    • By dfile
      I am running ProcessWire 3.0.165 but $input->urlSegmentLast or $input->urlSegment(-1) does not work as expected.
      Or do I something wrong?
      Thank you.

    • By bramwolf
      Hi Guys,

      I found here: https://processwire.com/docs/selectors/#finding2 that I can exclude results from my $pages->find($selctor); query by using parent!=123 ( parent ID ) But I was wondering if I can
      also do so based on the parent template? I've tried doing it by itterating over the matches array and dropping the matches with the parent but since the result is limited for use with the paginator
      it only drops the items from the batch displayed on this page. Say from the results within matches 0 - 20 and not the entire 0 - 220.

      Anybody have a idea of how to achieve this? 🙂

      Thanks in advace!
    • By LAPS
      I've pages using the custom-page-template and I would like to display a simple message at the top of the page form when editing those pages in the Admin.
      I thought about hooking ProcessPageEdit::buildForm() but I do not well how to use that hook in order to display the message just for the custom-page-template pages.
      Any help?
      UPDATE: Solution found
      wire()->addHookAfter('ProcessPageEdit::buildForm', function(HookEvent $event) { $ProcessPageEdit = $event->object; $form = $event->arguments('form'); switch ($ProcessPageEdit->getPage()->template->name) { case 'custom-page-template': $form->prependMarkup("<div style='margin-bottom: 3.6em; margin-top: 1em; background: #ffd;'>MY MESSAGE</div>"); break; default: // do nothing } }); Any improvement is welcome!
    • By louisstephens
      So I ran into a strange error this morning when trying to publish a page. I went to publish a new page under "clients", but I get an error that says "Cannot be published until errors are corrected". I thought perhaps I had missed a required field so I checked, but none of the fields are marked as required. I then checked to see if I could just add a basic page (default basic-page.php template) under the homepage, but I get the exact same error when trying to publish. When looking at the template, I don't see any error messages being displayed above any fields.
      The odd thing I found though was if I got to "settings"  and uncheck "unpublished", I can then publish the page without errors. I did upgrade earlier today to the newest version to hopefully fix an issue I had yesterday (which it did). Has anyone run into this error before? 
      Well, after a lot of staring and pulling my hair out, I found the issues. I had installed multi-language support sometime ago (and due to the project changing, had to remove it). Apparently in my haste, I did not remove all the dependencies so it was still trying to check for the multi-language title (I am guessing) even though it actually wasnt on the page. I went through the database and removed it and can now save/publish pages without issues. 
  • Create New...