Jump to content

Global settings, your way?


kaz
 Share

Recommended Posts

How do you set up global settings?

I did it this way:
I do a template settings (without php file). I made fields, company, name, city, phone, ... which are included in the template. Then I created a Settings page in the Tree with the Settings template, and declared the page as Hidden in the Page Settings. I retrieve the content via page ID.

Is this a common way? How do you implement global settings?

Link to comment
Share on other sites

3 hours ago, kaz said:

Then I created a Settings page in the Tree with the Settings template, and declared the page as Hidden in the Page Settings. I retrieve the content via page ID.

I do it very similar. I use a settings page with a unique template name where the family settings are restricted to use it only once (for a single page). Then I can connect to the content by using a selector with the template name. This way it is save, even if later the page gets deleted (by accident) and recreated. Also the user is free to rename its title and URL without interfering the content pickup in my initial codes. (Selector without ID, path, name, title, etc)

For contact information I used a Pro Field of type Textareas some years, that was named contact. It subfields have names like company, phone, email, address or street zip city, etc. Including links of social platforms etc. Now I use the newer Pro Field type Combo(!) for this, as it allows more flexibility. 
In the site/templates/_init.php I use a snippet like this to serve a shortcut for the use in my templates to this content: 

// object: firstname, lastname, phone, mobile, email, ...
$contact = (object) $pages->get('template=my-unique-templatename')->contact->data;

 

  • Like 2
Link to comment
Share on other sites

On 7/28/2021 at 12:52 PM, horst said:

I do it very similar. I use a settings page with a unique template name where the family settings are restricted to use it only once (for a single page). Then I can connect to the content by using a selector with the template name. This way it is save, even if later the page gets deleted (by accident) and recreated. Also the user is free to rename its title and URL without interfering the content pickup in my initial codes. (Selector without ID, path, name, title, etc)

For contact information I used a Pro Field of type Textareas some years, that was named contact. It subfields have names like company, phone, email, address or street zip city, etc. Including links of social platforms etc. Now I use the newer Pro Field type Combo(!) for this, as it allows more flexibility. 
In the site/templates/_init.php I use a snippet like this to serve a shortcut for the use in my templates to this content: 

// object: firstname, lastname, phone, mobile, email, ...
$contact = (object) $pages->get('template=my-unique-templatename')->contact->data;

 

@horst I have never used the combo field. This is interesting, I tried to test it. I have defined a combo field 'setting' with a few subfields, company (setting_company), name, street, and so on.
I created a template with these field, and assigned it to a new page.

The echo is not working, I can't get the data. No error message, it just keeps empty.

echo $page->setting->setting_company;
echo $pages->get('1052')->setting->setting_company;

The first line (Using your Combo field from template files) I have from: ProFields: Combo field.

How do you retrieve the data, from the page, from the template, from the field?

Link to comment
Share on other sites

On 7/28/2021 at 2:54 AM, kaz said:

Is this a common way? How do you implement global settings?

Same way except I like to put it within the Home page, under a Website Options tab. 

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