Vigilante Posted January 1, 2020 Share Posted January 1, 2020 I have a feeling I know the answer, but maybe there is a simpler way. Basically, in order to avoid saving any hardcoded info in a template file, I'd rather store this data in some kind of global data set or 'settings' and then pull the value into templates as needed. A simple example would be a company phone number, or an administrative email address. Rather than put these things hardcoded into the template that needs them, I'd rather call them up as some kind of global data as needed. And then of course this would make it easy to edit this data in the backend. My guess is that you would have me create a special "page" using a custom template with a whole bunch of fields for every kind of custom data I need. I guess this would be fine, but it would require creating lots of fields which I think would clutter the fields area up. The objective is just to have some place in the admin where a bunch of random things could be saved which may be used from any number of templates. And is easy to edit by the client. Link to comment Share on other sites More sharing options...
toni Posted January 1, 2020 Share Posted January 1, 2020 @Vigilante A config page with simple textfields for storing settings might be the best way to go. Another option would be your config.php . But in your case this is rather inappropriate as it might be hard to edit for your client. By the way instead of creating several fields in your config page you could also create one text field and put a json object in it which you could access and parse when needed. (provided the customer can handle json.) Link to comment Share on other sites More sharing options...
dragan Posted January 1, 2020 Share Posted January 1, 2020 @Vigilante That's exactly where (the often overlooked) Pro field "Functional Fields" shines. It does exactly what you are looking for. https://processwire.com/blog/posts/functional-fields/ Or you could use the Textareas field: https://processwire.com/store/pro-fields/textareas/The big advantage is that no matter how many fields you are using, behind the scenes it always just counts as one single field. 1 Link to comment Share on other sites More sharing options...
toni Posted January 1, 2020 Share Posted January 1, 2020 ... and also in addition to a json object as I suggested above you could also simply use a plain textfield and store your ini there like: [names] me = "Hello" you = "World" [urls] first = "http://www.example.com" in your template you could access it as array with: print_r(parse_ini_string($page->ini)) Array ( [me] => Hello [you] => World [first] => http://www.example.com ) Link to comment Share on other sites More sharing options...
Macrura Posted January 1, 2020 Share Posted January 1, 2020 also settings factory 2 Link to comment Share on other sites More sharing options...
adrian Posted January 2, 2020 Share Posted January 2, 2020 5 hours ago, Macrura said: also settings factory SettingsFactory is awesome - I use it on almost all sites now! Link to comment Share on other sites More sharing options...
toni Posted January 2, 2020 Share Posted January 2, 2020 SettingsFactory && Functional Fields . Nice! Link to comment Share on other sites More sharing options...
psy Posted January 2, 2020 Share Posted January 2, 2020 9 hours ago, dragan said: That's exactly where (the often overlooked) Pro field "Functional Fields" shines. It does exactly what you are looking for. I usually do a combination of both - separate 'Business Info' page that stores stuff like logo versions, etc and a functional field that stores common text phrases. All editable by admin on that page and (I believe as don't use it), editable for multi-lang sites. Even go so far sometimes to make the page a link in the admin main menu, with or without a custom module Link to comment Share on other sites More sharing options...
gmclelland Posted January 2, 2020 Share Posted January 2, 2020 Haven't used it yet, but I think I read that Mystique is also a good module for this kind of stuff. I have also used SettingsFactory and can say that it works great. 1 Link to comment Share on other sites More sharing options...
ukyo Posted January 3, 2020 Share Posted January 3, 2020 20 hours ago, gmclelland said: Haven't used it yet, but I think I read that Mystique is also a good module for this kind of stuff. I have also used SettingsFactory and can say that it works great. Yes, it's possible to do these kind of stuff. Create 1 Mystique field and do what you want with that field. Mystique config files Mystique seo configs Mystique admin edit for seo configs 2 Link to comment Share on other sites More sharing options...
Pixrael Posted January 3, 2020 Share Posted January 3, 2020 https://modules.processwire.com/modules/fieldtype-yaml/ Link to comment Share on other sites More sharing options...
Pixrael Posted January 3, 2020 Share Posted January 3, 2020 https://processwire.com/blog/posts/pw-3.0.133/#new-page-gt-meta-method <-- the new kid on the block 2 Link to comment Share on other sites More sharing options...
Vigilante Posted January 6, 2020 Author Share Posted January 6, 2020 On 1/3/2020 at 2:53 PM, Pixrael said: https://processwire.com/blog/posts/pw-3.0.133/#new-page-gt-meta-method <-- the new kid on the block This one is nice, but also per-page scoped, so not really global. Also at one point of the lifecycle do you actually set those variables? Are they persistent? I assume we're not setting the all variables in the same template they are used, on every page load, so is there some other administrative area where you can set the data once to use? On 1/1/2020 at 3:35 PM, dragan said: That's exactly where (the often overlooked) Pro field "Functional Fields" shines. It does exactly what you are looking for. https://processwire.com/blog/posts/functional-fields/ This is also nice, but not in the current release yet? I don't have these available in my version. Also, it seems to focus on template-specific fields, rather than globally available data. Although I assume maybe you can access this data of one page from another page. Even still that's a bit clunky, trying to remember which page has particular fields you need, etc. On 1/1/2020 at 3:35 PM, dragan said: Or you could use the Textareas field: https://processwire.com/store/pro-fields/textareas/The big advantage is that no matter how many fields you are using, behind the scenes it always just counts as one single field. It's possible this client I'm working on, has Pro Fields. I'll double-check. But this is also per-template data. I guess that's just how PW works, haha. I would be nice to really have a completely separated, almost non-page area somewhere in admin, just to define site-wide data from the user admin. Like a custom admin page of arbitrary fields. On 1/1/2020 at 10:06 PM, adrian said: SettingsFactory is awesome - I use it on almost all sites now! That might be a winner. Link to comment Share on other sites More sharing options...
dragan Posted January 6, 2020 Share Posted January 6, 2020 1 hour ago, Vigilante said: This is also nice, but not in the current release yet? I don't have these available in my version. As noted, this is also part of Pro Fields, and it's been around for quite some time. On second thought, maybe that's not ideal, considering all the other options you have. 1 hour ago, Vigilante said: Also, it seems to focus on template-specific fields, rather than globally available data. Although I assume maybe you can access this data of one page from another page. Even still that's a bit clunky, trying to remember which page has particular fields you need, etc. I don't know why you keep repeating this. Use an _init.php that you prepend everywhere. In that file, grab those global field values from that one specific page you've set up for just that reason, and you're set. You'll be able to use these vars from anywhere. You don't even need a physical template file for such a "settings" page, since you don't need a frontend view for that. 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted January 6, 2020 Share Posted January 6, 2020 Just to give you another option. Check out this module by @ryan himself. I did not find it in the modules directory. And it did not receive much attention from the author in a while. But it did the job when I used it (a few years ago ?) . As far as I remember it stores custom data written in site/config.php. And it is manageable from admin without the need to create pages. 1 Link to comment Share on other sites More sharing options...
Vigilante Posted January 7, 2020 Author Share Posted January 7, 2020 I've been trying Settings Factory and I simply used the kitchen sink file for testing. For some reason these errors come up on nearly every page load of the admin, not even editing my custom settings page, they just show up every time the page refreshes: I have valid URLs and Emails but these keep popping up all the time. Link to comment Share on other sites More sharing options...
Macrura Posted January 7, 2020 Share Posted January 7, 2020 @Vigilante, sorry to hear about that; Probably best to just remove those 2 fields from the kitchen sink file. I'll run a test here to see if those are caused by any recent changes in the fields or admin. Also, FYI, the reason those show up everywhere is that settings are stored in module config and those do load in the admin; So for example if you have invalid JSON you may see an error everywhere.... Link to comment Share on other sites More sharing options...
Macrura Posted January 7, 2020 Share Posted January 7, 2020 @Vigilante, testing this now, but not seeing any problems here with the kitchen sink file, either PHP or JSON version. if i do remove the http:// from the URL field, i do get the notice, but only once. In terms of the email address, the browser validation won't let me enter an invalid email address, can you post the email address you put in that field? 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