Macrura

Settings Factory

Recommended Posts

sf_logo.png.273967076f19a5f3601ac83abc3cef49.png

This is the new topic for the Settings Factory module (formerly known as Settings Train).

Repo:

https://github.com/outflux3/SettingsFactory

I'm not sure what versions this is compatible with, it has only been tested on 3.x branch;
it is not namespaced, and i'm not sure if namespacing is necessary or a benefit for this module; if any namespace or module gurus can weigh in on this, let me know. I'm also not sure if there needs to be a minimum php version;

I have one live site using this now and it's working great; But before submitting to mods directory, would be better if there was some additional testing by other users.

  • Like 10

Share this post


Link to post
Share on other sites

Hi Marc

Much prefer this name - makes more sense. Will test it out (functionality-wise) today.

You don't need to namespace it if you're maintaing compatibility with PW-legacy. I don't namespace my module files, but only everything outside of them. For example, Typographer uses two namespaces: Rockett and Typographer, both of which are imported via the PW class loader. Everything should work fine in legacy, so long as you don't use any features that are only available after 3.0.62 as legacy will probably only be brought up to speed when the next 3.x stable comes out. 

In terms of PHP compatibility, I make it a rule to support only 5.6+, as it is currently the oldest version with security support. With that said, my phpfmt (mentioned below) is configured to use PHP 5.4-style arrays.

Some other recommendations from my side:

  1. Be consistent with spaces/tabs. Tabs are generally frowned upon on the PSR side of things, but it's really up to you, provided it's consistent. I use four spaces for indentation, and I also use phpfmt in Sublime to automatically format my code.
  2. in processForm(), you're pulling in the page title within the walls of a translation helper. As far as I know, this doesn't work, so you'll need to use sprintf to import the page title: sprintf($this->_('Saved: %s'), $this->wire('page')->title)
  3. wire is imported into the Process, so can use $this->wire(…) everywhere that doesn't have a static scope, instead of the wire() helper.

Hope that helps. 😊

  • Like 3

Share this post


Link to post
Share on other sites

Thanks @Mike Rockett!

5 hours ago, Mike Rockett said:

Be consistent with spaces/tabs. Tabs are generally frowned upon on the PSR side of things, but it's really up to you, provided it's consistent. I use four spaces for indentation, and I also use phpfmt in Sublime to automatically format my code.

currently as far as i know/can see in Sublime, the module follows the PW coding guide, so only uses tabs

I fixed all the other items according to your recommendations, commit after testing..

Share this post


Link to post
Share on other sites

You're welcome.

25 minutes ago, Macrura said:

currently as far as i know/can see in Sublime, the module follows the PW coding guide, so only uses tabs

The GH editor is showing me spaces in some places, and so the indentation appears inconsistent. 

I wasn't actually aware of a style guide for PW (I've now seen it). I tend to stick to PSR1 and 2 along with the following configuration:

Spoiler

[
	"AddMissingParentheses",
	"AutoSemicolon",
	"ClassToSelf",
	"DocBlockToComment",
	"DoubleToSingleQuote",
	"EchoToPrint",
	"GeneratePHPDoc",
	"IndentTernaryConditions",
	"MergeElseIf",
	"NewLineBeforeReturn",
	"OrderMethod",
	"OrganizeClass",
	"PrettyPrintDocBlocks",
	"PSR2EmptyFunction",
	"ReindentSwitchBlocks",
	"RemoveSemicolonAfterCurly",
	"RemoveUseLeadingSlash",
	"ReplaceIsNull",
	"ReturnNull",
	"ShortArray",
	"StripNewlineAfterCurlyOpen",
	"StripSpaceWithinControlStructures",
	"WrongConstructorName"
],

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Oh, and just to follow up on the PHP compatibility. It's currently compatible with 5.4+. If the square array notation is changed in both files (three small occurrences in total), then it supports 5.2+.

  • Like 1

Share this post


Link to post
Share on other sites

By strange coincidence, I was just thinking that maybe PW should have a standard EditorConfig file as part of the suite. Whilst it does not address all of the code styling issues raised above, it would allow us to all get the tabs/spaces/line endings/whitespace trimming right for this project by just using an editor that either supports EditorConfig out of the box, or via a plugin. I've started using it on my current project and it seems to work quite well.

  • Like 4

Share this post


Link to post
Share on other sites
26 minutes ago, netcarver said:

By strange coincidence, I was just thinking that maybe PW should have a standard EditorConfig file as part of the suite. Whilst it does not address all of the code styling issues raised above, it would allow us to all get the tabs/spaces/line endings/whitespace trimming right for this project by just using an editor that either supports EditorConfig out of the box, or via a plugin. I've started using it on my current project and it seems to work quite well.

Didn't know there was some sort of universal config like that. Tried it out in Sublime, works well!

Share this post


Link to post
Share on other sites
13 hours ago, Mike Rockett said:

Tabs are generally frowned upon on the PSR side of things

Tabs 4 Life, brah! There is no more definitive authority than Richard Hendricks:

(I've posted that before but could not resist)

But seriously, the PW code style gets things so right. The braces style too. Some reasoned argument:
https://github.com/php-fig-rectified/fig-rectified-standards/blob/master/Reasoning-Tabs-vs-Spaces.md
https://github.com/php-fig-rectified/fig-rectified-standards/blob/master/Reasoning-Brace-Styles.md

 

  • Like 1
  • Haha 1

Share this post


Link to post
Share on other sites

I would have taken an exception in this particular case :)

  • Like 1

Share this post


Link to post
Share on other sites

@Robin S They make some valid arguments, though I'm used to fig. On the flip side, their readmes use spaces for indentation, even in code blocks that state that a tab should be used instead. ;-) Good video though - hadn't seen that before.

Edit: Anyways, let's not hijack the thread - we could always open up a new one to discuss these things. (Sorry, Marc...)

Share this post


Link to post
Share on other sites
8 minutes ago, adrianromega said:

Interesting module, but how are you suppose to access all the defined fields in the front-end ?

I'm working on the github wiki which will include those instructions, but here it is in a nutshell:

Once you have created the process page for the settings, those settings are available using the process name, so if you made a page with the name theme-settings, you would do this:

$factory = $modules->get("SettingsFactory");
$themeSettings = $factory->getSettings('theme-settings');

the settings are delivered as a WireArray (or can be delivered as a plain array getSettingsArray('name-of-process); Here is the bar dump of those settings, using default wireArray;

59e2496382961_My_Great_Site__The_Best_Site_In_the_Universe.jpg.d38e21898e8c5b3ccc15fcf637f38993.jpg

In some scenarios i'm getting the raw array and merging it with some other hardcoded array, like for outputting JSON-LD schema:

Person.schema.php:

<?php namespace ProcessWire;

if(empty($item)) $item = $page;
if(!isset($tag)) $tag = true;

$jsonld = array(
	"@context" 		=> $tag ? "http://schema.org/" : '',
	'@type'			=> 'Person',
	'mainEntityOfPage' => array(
		'@type' => "WebPage",
		'@id'	=> $pages->get(1)->httpUrl,
	)
);

$factory = $modules->get('SettingsFactory');
$personSchema = $factory->getSettingsArray('schema-person');
$jsonld = array_merge($jsonld, $personSchema);

// add image here...
$profileMedia = wire('pages')->get("template=media, media_roles.name=schema-profile, images.count>0");
if($profileMedia->id) {
	$image = $profileMedia->images->first()->width(696);
	$jsonld['image']		= array(
		"@type" => "ImageObject",
		'url'	=> $image->httpUrl,
		'height'=> $image->height,
		'width' => $image->width
	);
}

$jsonld = array_filter($jsonld);
if(!$tag) {
	return $jsonld;
} else {
	if($user->isLoggedin()) {
		$jsonld = json_encode($jsonld, JSON_PRETTY_PRINT);
	} else {
		$jsonld = json_encode($jsonld);
	}
	echo '<script type="application/ld+json">' . $jsonld . '</script>';
}

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Thanks for info, now is all clear.

Using your module you can define all kind of fields, except for InputfieldImage and InputfieldFile.... what is your suggestion to have in "settings"  fields for images or files (for logoes, backgound image, etc) ?

I hope you understand what I mean....

 

Share this post


Link to post
Share on other sites
On 10/23/2017 at 12:02 PM, adrianromega said:

what is your suggestion to have in "settings"  fields for images or files (for logoes, backgound image, etc) ?

Since i typically maintain separate pages for those types of media (in a media library for every site), it is just a matter of setting up page select field. I use selectize so that the user can see what they are selecting. Also if i use a page for logo, then they can update the logo from the media library without having to change the setting; or they can add several logos to the media library and then select which one to use on the settings page.

I don't yet know how to support image/file fields natively in this module, although since the settings pages themselves are pages of template admin, it might be possible. I was actually able to use both image and file fields and upload an image, however there are still errors with the value of the inputfield not yet working...

In other news, here are some new screenshots of settings panels using UiKit theme, including a working example of using  WireTabs:

59f4d949123a1_Theme_Settings__ProcessWire__localhost.thumb.jpg.bfb1461cded2a615e778a50d8bea6833.jpg

59f4d950c8e71_WireTabs_Testing__ProcessWire__localhost.thumb.jpg.13ddd192e24c657e684b2a01e9e95db0.jpg

 

 

 

  • Like 5

Share this post


Link to post
Share on other sites

thanks for your reply.

I have tried also the new version with support for InputfieldWrapper.

Based on your example, wiretabs-example.php, I have tried to use 2 InputfieldFieldsets inside first wiretab (InputfieldWrapper inside InputfieldWrapper), the display of fields is fine, but it is not saving values of fields properly...depends on the position of the nested InputfieldWrappers, some values are saved, some are not. With only one InputfieldWrapper inside another InputfieldWrapper, all is fine, but with more nested InputfieldWrappers, something is wrong.

for the config below for example, is not saving the field values form the first InputfieldFieldset.

 

<?php

/**
 * since you can only return 1 array to the module, you have to wrap 
 * the tabs in an inputfield wrapper
 */
$inputfields = new InputfieldWrapper();

//---------------------------------------------------
$general = [
    [
        'name' => 'site_name',
        'label' => __('Site Name'),
        'type' => 'InputfieldText',
        'value' => ''
    ],
    [
        'name' => 'email_address',
        'label' => __('E-mail'),
        'type' => 'InputfieldEmail',
        'value' => ''
    ],
    [
        'name' => 'telephone',
        'label' => __('Telephone'),
        'type' => 'InputfieldText',
        'value' => ''
    ],
    [
        'name' => 'fax',
        'label' => __('Fax'),
        'type' => 'InputfieldText',
        'value' => ''
    ],
];



$general2 = [
    [
        'name' => 'set_1',
        'label' => __('Setting 1'),
        'type' => 'InputfieldText',
        'value' => ''
    ],
    [
        'name' => 'set_2',
        'label' => __('Setting 2'),
        'type' => 'InputfieldText',
        'value' => ''
    ]
];

$general3 = [
    [
        'name' => 'set_3',
        'label' => __('Setting 3'),
        'type' => 'InputfieldText',
        'value' => ''
    ],
    [
        'name' => 'set_4',
        'label' => __('Setting 4'),
        'type' => 'InputfieldText',
        'value' => ''
    ] 
];



$tab = new InputfieldWrapper();
$tab->attr('title', 'General');
$tab->attr('class', 'WireTab');




$advanced = new InputfieldFieldset();
$advanced->label = __('Advanced Settings');
$advanced->description = __('These settings are not required');
$advanced->columnWidth = 50;
$advanced->add($general2);
$tab->add($advanced);



$advanced = new InputfieldFieldset();
$advanced->label = __('Advanced Settings');
$advanced->description = __('These settings are not required');
$advanced->columnWidth = 50;
$advanced->add($general3);
$tab->add($advanced);



$tab->add($general);

$inputfields->append($tab);

//---------------------------------------------------
$location = [
    [
        'name' => 'address',
        'label' => __('Address'),
        'type' => 'InputfieldText',
        'required' => true,
        'value' => ''
    ],
    [
        'name' => 'postal_code',
        'label' => __('Postal code'),
        'type' => 'InputfieldText',
        'required' => true,
        'value' => '',
        'columnWidth' => 33
    ],
    [
        'name' => 'city',
        'label' => __('City'),
        'type' => 'InputfieldText',
        'required' => true,
        'value' => '',
        'columnWidth' => 67
    ],
];

$tab = new InputfieldWrapper();
$tab->attr('title', 'Location');
$tab->attr('class', 'WireTab');
$tab->add($location);
$inputfields->append($tab);

//---------------------------------------------------


return $inputfields;

 

Share this post


Link to post
Share on other sites

ok i think i have fixed this, and improved the extraction process for the inputfields. Can you try the latest version?

Share this post


Link to post
Share on other sites

@adrianromega - thanks for taking it for a test drive, and identifying that problem!

I ended up rewriting the method that extracts the inputfields and now it should work a lot better thanks to your testing of that scenario.

 

Share this post


Link to post
Share on other sites

@Macrura Great module. Thank you for your work. Just curious is there some limitation of input field types? 

Share this post


Link to post
Share on other sites
1 hour ago, Zeka said:

Great module. Thank you for your work. Just curious is there some limitation of input field types? 

It is probably limited to the types of fields you can use generally in module configs, and currently there is no way to handle custom processing of form data, it uses the default $form->process() function from the core; If there are any specific fields you want to test let me know and i'll give them a go; The obvious ones that won't work are files and images, as well as any profileds like tables, repeaters and stuff like that;

Share this post


Link to post
Share on other sites

Actually I was thinking about Profields ( tables, multiplier). So there are no repeatable field types that we can use with the module. 

Share this post


Link to post
Share on other sites
3 hours ago, Zeka said:

So there are no repeatable field types that we can use with the module. 

Yeah, i haven't found any way to do repeatable content yet, but it could be possible to roll your own multiplier field using text inputs and some javascript. If i get around to that i will post how it is done..

Share this post


Link to post
Share on other sites

the input form is all native PW; so you just supply your array of field definitions using the correct keys for that inputfield type;

no graphical ui would be possible, but there is a kitchen sink file where you just grab the type of inputfield you want, paste it in to your fields array, change the settings and bob's your uncle.

  • Like 2

Share this post


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 louisstephens
      I have a script that is pulling in a json feed (will be attached to a cron job later) which looks like:
      $http = new WireHttp(); // Get the contents of a URL $response = $http->get("feed_url"); if($response !== false) { $decodedFeed = json_decode($response); } Everything there works well and I can pull the id, title, status (updated, new, sold) and other items from the decoded feed in a foreach loop. My whole goal is to create pages from the feed, but if the page has already been created, with all the same exact items from the json feed, I will need to "skip" over it.
      So far, I am running into a roadblock with my checks. I guess I need to compare the json to all my pages and their values and:
      1. If an id already exists, check to see if a fields data has been updated and then update the page,
      2. If an id exists and all fields are unchanged, skip adding that page
       
      $http = new WireHttp(); // Get the contents of a URL $response = $http->get("feed_url"); if($response !== false) { $decodedFeed = json_decode($response); foreach($decodedFeed as $feed) { $u = new Page(); $u->template = $templates->get("basic-page"); $u->parent = $pages->get("/development/"); $u->name = $feed->title = $feed->id; $u->title = $feed->title; $u->status = $feed->status $u->body = $feed->title; $u->save(); $u->setOutputFormatting(false); } } else { echo "HTTP request failed: " . $http->getError(); } I am really just hung up on how to do the current page checks and matching them with the json field data.
    • By Noel Boss
      ProcessWire & Vue.js — a Lovestory
      Introducing the all new ICF Conference Website
        The new ICF Conference Page — Fearless
      » What would happen if we were equipped to fearlessly face the daily challenges and live a life without fear? «
      This question is at the core of our next ICF Conference in 2019 in Zurich. Its also the question we set out to answer in terms of developing the new website; the all new ICF Conference website is our most advanced website in terms of technology, designed to take advantage of the latest web-technologies.
      Its a brand new design powered by a lean setup, using ProcessWire for easy content management and a slick frontend based on Vue.js, Quasar and a heavily customized Uikit theme.
        Technology-stack — From backend to frontend, technologies that are fun, easy and fast to develop with We built on the ICF Ladieslounge website as a solid foundation and took our learnings from building our last Conference Booklet PWA (Progressive Web App) and applied it to the new website.
      Some highlights of the new ICF Conference website:
      Completely decoupled backend and frontend Custom design based on Uikit frontend framework Changing of languages happens instantly, no page-reload required Easy content updates thanks to ProcessWire All data is transferred using a single request returning custom JSON



      » Continue reading on Medium
      And please don't forget to clap and share: 

       
    • By Noel Boss
      Page Query Boss
      Build complex nested queries containing multiple fields and pages and return an array or JSON. This is useful to fetch data for SPA and PWA.
      You can use the Module to transform a ProcessWire Page or PageArray – even RepeaterMatrixPageArrays – into an array or JSON. Queries can be nested and contain closures as callback functions. Some field-types are transformed automatically, like Pageimages or MapMarker.
      Installation
      Via ProcessWire Backend
      It is recommended to install the Module via the ProcessWire admin "Modules" > "Site" > "Add New" > "Add Module from Directory" using the PageQueryBoss class name.
      Manually
      Download the files from Github or the ProcessWire repository: https://modules.processwire.com/modules/page-query-builder/
      Copy all of the files for this module into /site/modules/PageQueryBoss/ Go to “Modules > Refresh” in your admin, and then click “install” for the this module. Module Methods
      There are two main methods:
      Return query as JSON
      $page->pageQueryJson($query); Return query as Array
      $page->pageQueryArray($query); Building the query
      The query can contain key and value pairs, or only keys. It can be nested and 
      contain closures for dynamic values. To illustrate a short example:
      // simple query: $query = [ 'height', 'floors', ]; $pages->find('template=skyscraper')->pageQueryJson($query); Queries can be nested, contain page names, template names or contain functions and ProcessWire selectors:
      // simple query: $query = [ 'height', 'floors', 'images', // < some fileds contain default sub-queries to return data 'files' => [ // but you can also overrdide these defaults: 'filename' 'ext', 'url', ], // Assuming there are child pages with the architec template, or a // field name with a page relation to architects 'architect' => [ // sub-query 'name', 'email' ], // queries can contain closure functions that return dynamic content 'querytime' => function($parent){ return "Query for $parent->title was built ".time(); } ]; $pages->find('template=skyscraper')->pageQueryJson($query); Keys:
      A single fieldname; height or floors or architects 
      The Module can handle the following fields:
      Strings, Dates, Integer… any default one-dimensional value Page references Pageimages Pagefiles PageArray MapMarker FieldtypeFunctional A template name; skyscraper or city
      Name of a child page (page.child.name=pagename); my-page-name A ProcessWire selector; template=building, floors>=25
      A new name for the returned index passed by a # delimiter:
      // the field skyscraper will be renamed to "building": $query = ["skyscraper`#building`"]  
      Key value pars:
      Any of the keys above (1-5) with an new nested sub-query array:
      $query = [ 'skyscraper' => [ 'height', 'floors' ], 'architect' => [ 'title', 'email' ], ]  
      A named key and a closure function to process and return a query. The closure gets the parent object as argument:
      $query = [ 'architecs' => function($parent) { $architects = $parent->find('template=architect'); return $architects->arrayQuery(['name', 'email']); // or return $architects->explode('name, email'); } ] Real life example:
      $query = [ 'title', 'subtitle', // naming the key invitation 'template=Invitation, limit=1#invitation' => [ 'title', 'subtitle', 'body', ], // returns global speakers and local ones... 'speakers' => function($page){ $speakers = $page->speaker_relation; $speakers = $speakers->prepend(wire('pages')->find('template=Speaker, global=1, sort=-id')); // build a query of the speakers with return $speakers->arrayQuery([ 'title#name', // rename title field to name 'subtitle#ministry', // rename subtitle field to ministry 'links' => [ 'linklabel#label', // rename linklabel field to minlabelistry 'link' ], ]); }, 'Program' => [ // Child Pages with template=Program 'title', 'summary', 'start' => function($parent){ // calculate the startdate from timetables return $parent->children->first->date; }, 'end' => function($parent){ // calculate the endate from timetables return $parent->children->last->date; }, 'Timetable' => [ 'date', // date 'timetable#entry'=> [ 'time#start', // time 'time_until#end', // time 'subtitle#description', // entry title ], ], ], // ProcessWire selector, selecting children > name result "location" 'template=Location, limit=1#location' => [ 'title#city', // summary title field to city 'body', 'country', 'venue', 'summary#address', // rename summary field to address 'link#tickets', // rename ticket link 'map', // Mapmarker field, automatically transformed 'images', 'infos#categories' => [ // repeater matrix! > rename to categories 'title#name', // rename title field to name 'entries' => [ // nested repeater matrix! 'title', 'body' ] ], ], ]; if ($input->urlSegment1 === 'json') { header('Content-type: application/json'); echo $page->pageQueryJson($query); exit(); } Module default settings
      The modules settings are public. They can be directly modified, for example:
      $modules->get('PageQueryBoss')->debug = true; $modules->get('PageQueryBoss')->defaults = []; // reset all defaults Default queries for fields:
      Some field-types or templates come with default selectors, like Pageimages etc. These are the default queries:
      // Access and modify default queries: $modules->get('PageQueryBoss')->defaults['queries'] … public $defaults = [ 'queries' => [ 'Pageimages' => [ 'basename', 'url', 'httpUrl', 'description', 'ext', 'focus', ], 'Pagefiles' => [ 'basename', 'url', 'httpUrl', 'description', 'ext', 'filesize', 'filesizeStr', 'hash', ], 'MapMarker' => [ 'lat', 'lng', 'zoom', 'address', ], 'User' => [ 'name', 'email', ], ], ]; These defaults will only be used if there is no nested sub-query for the respective type. If you query a field with complex data and do not provide a sub-query, it will be transformed accordingly:
      $page->pageQueryArry(['images']); // returns something like this 'images' => [ 'basename', 'url', 'httpUrl', 'description', 'ext', 'focus'=> [ 'top', 'left', 'zoom', 'default', 'str', ] ]; You can always provide your own sub-query, so the defaults will not be used:
      $page->pageQueryArry([ 'images' => [ 'filename', 'description' ], ]); Overriding default queries:
      You can also override the defaults, for example
      $modules->get('PageQueryBoss')->defaults['queries']['Pageimages'] = [ 'basename', 'url', 'description', ]; Index of nested elements
      The index for nested elements can be adjusted. This is also done with defaults. There are 3 possibilities:
      Nested by name (default) Nested by ID Nested by numerical index Named index (default):
      This is the default setting. If you have a field that contains sub-items, the name will be the key in the results:
      // example $pagesByName = [ 'page-1-name' => [ 'title' => "Page one title", 'name' => 'page-1-name', ], 'page-2-name' => [ 'title' => "Page two title", 'name' => 'page-2-name', ] ] ID based index:
      If an object is listed in $defaults['index-id'] the id will be the key in the results. Currently, no items are listed as defaults for id-based index:
      // Set pages to get ID based index: $modules->get('PageQueryBoss')->defaults['index-id']['Page']; // Example return array: $pagesById = [ 123 => [ 'title' => "Page one title", 'name' => 123, ], 124 => [ 'title' => "Page two title", 'name' => 124, ] ] Number based index
      By default, a couple of fields are transformed automatically to contain numbered indexes:
      // objects or template names that should use numerical indexes for children instead of names $defaults['index-n'] => [ 'Pageimage', 'Pagefile', 'RepeaterMatrixPage', ]; // example $images = [ 0 => [ 'filename' => "image1.jpg", ], 1 => [ 'filename' => "image2.jpg", ] ] Tipp: When you remove the key 'Pageimage' from $defaults['index-n'], the index will again be name-based.
       
      Help-fill closures & tipps:
      These are few helpfill closure functions you might want to use or could help as a
      starting point for your own (let me know if you have your own):

      Get an overview of languages:
          $query = ['languages' => function($page){         $ar = [];         $l=0;         foreach (wire('languages') as $language) {             // build the json url with segment 1             $ar[$l]['url']= $page->localHttpUrl($language).wire('input')->urlSegment1;             $ar[$l]['name'] = $language->name == 'default' ? 'en' : $language->name;             $ar[$l]['title'] = $language->getLanguageValue($language, 'title');             $ar[$l]['active'] = $language->id == wire('user')->language->id;             $l++;         }         return $ar;     }]; Get county info from ContinentsAndCountries Module
      Using the [ContinentsAndCountries Module](https://modules.processwire.com/modules/continents-and-countries/) you can extract iso
      code and names for countries:
          $query = ['country' => function($page){         $c = wire('modules')->get('ContinentsAndCountries')->findBy('countries', array('name', 'iso', 'code'),['code' =>$page->country]);         return count($c) ? (array) $c[count($c)-1] : null;     }]; Custom strings from a RepeaterTable for interface
      Using a RepeaterMatrix you can create template string for your frontend. This is
      usefull for buttons, labels etc. The following code uses a repeater with the
      name `strings` has a `key` and a `body` field, the returned array contains the `key` field as,
      you guess, keys and the `body` field as values:
          // build custom translations     $query = ['strings' => function($page){         return array_column($page->get('strings')->each(['key', 'body']), 'body', 'key');     }]; Multilanguage with default language fallback
      Using the following setup you can handle multilanguage and return your default
      language if the requested language does not exist. The url is composed like so:
      `page/path/{language}/{content-type}` for example: `api/icf/zurich/conference/2019/de/json`
       
          // get contenttype and language (or default language if not exists)     $lang = wire('languages')->get($input->urlSegment1);     if(!$lang instanceof Nullpage){         $user->language = $lang;     } else {         $lang = $user->language;     }     // contenttype segment 2 or 1 if language not present     $contenttype = $input->urlSegment2 ? $input->urlSegment2 : $input->urlSegment1;     if ($contenttype === 'json') {         header('Content-type: application/json');         echo $page->pageQueryJson($query);         exit();     } Debug
      The module respects wire('config')->debug. It integrates with TracyDebug. You can override it like so:
      // turns on debug output no mather what: $modules->get('PageQueryBoss')->debug = true; Todos
      Make defaults configurable via Backend. How could that be done in style with the default queries?
      Module in alpha Stage: Subject to change
      This module is in alpha stage … Query behaviour (especially selecting child-templates, renaming, naming etc)  could change
    • By Eunico Cornelius
      Hi, I am trying to create a PHP page in my website that is hidden and produce a plain JSON format. However, when I implement json_encode on my string, the result is not only a plain JSON but also a <!DOCTYPE HTML>.... I have created a new page and a new template that has it's cache disabled, but it still doesn't work.
      this is what my code looks like 
      <?PHP $useMain=false; $data = "[{'title':'AAAAA','url':'https://google.com'}]"; header('Content-Type: application/json'); echo json_encode($data); ?> This is what I currently get
      "[{'title':'AAAAA','url':'https:\/\/google.com'}]"<!DOCTYPE html><html>....</html> This is what I am trying to achieve
      "[{'title':'AAAAA','url':'https:\/\/google.com'}]" What am I missing here? I am also using ProCache.(dont know if it has any influence since I created and disable cache in a new template)
    • By h365
      Hi Guys,
      So i have a big piece of Json data for a Travel - Tour 
      all kinds of rates, dates, services and so on.. 
      The Structure of the Json slightly changes here and there depending on the Tour. 
      What would be the best way to import that data in processwire to make it easily searchable etc trough the API.. ? 
      I tried Multi Level Repeater Matrixes which are good and would do the job, but then i have no big options to search trough that data.. 
      Would really appreciate all input!
      Thanks so much