Jump to content

Recommended Posts

As described in this post (https://processwire.com/talk/topic/8551-custom-urls-for-pages/?p=82742) the option 'Name Format Children' under the tab 'Family' in template settings doesn't work properly and also not as expected. I had a look inside the code and made some changes which are working properly, which offers much more options, more consistency and less code too.

The result is the following. You have 3 Options for generating name and title, which could be combined in endless variations.
Name is always derived from title, same like creating pages manually.

  • type date: if function detects # character anywhere in the string, conversion will be: deletion of # and string will be used as format parameter for PHP date() function
  • type field: if string is a fieldname of the parent page the value of this field will be used
  • type string: if string doesn't fit to the 2 preceeding it will be taken as it is

All parts (separated by comma) will be composed in the order of setting. You can use unlimited numbers of parts

I made a pull request on github: https://github.com/ryancramerdesign/ProcessWire/pull/831

Example screenshots

Setting ...
post-1246-0-98447200-1418822310_thumb.jp

will result in
post-1246-0-97471800-1418822297_thumb.jp

 

  • Like 10

Share this post


Link to post
Share on other sites

That's ultimatly what most people wanted to use there. I mostly used something like this by now "\c\o\m\m\e\n\t-Ymd-His"

  • Like 1

Share this post


Link to post
Share on other sites

Looks great. But It seemed to me that "Name format for children" option should define name of the page, not title. On the screenshot it is title that gets generated.

Share this post


Link to post
Share on other sites

@Ivan

Yes, the title is generated and the name too, as a derivation from the title. (have a look at the system notice on top of the screenshot) Derivation works completely in the same way, if you add a page manually and type in the page title. I think thats what most user would expect.

You have read the post, where I described, how it is working actually (link in the first post of this topic). This way seems to be unlogical to me.

  • Like 1

Share this post


Link to post
Share on other sites

Yes, I took part in that conversation too. But it seems to me that the way it was supposed to work is to autogenerate name for a page on a pattern at creation time but not from the title. As there is no title on creation yet we could:

  • either generate name from parent fields, dates, custon text + numbers, or
  • apply the pattern on the first save (but not generate the title field by that pattern).

If using your solution we have to:

  • either not use title field for output as you probably would not want to use something like "prefix Wednezday...", or
  • save the page to generate name field value and then change the title once again.

I could misunderstand you as I did not apply you patch to the core.

Share this post


Link to post
Share on other sites

@ Ivan

Thats not true. Now you cannot use any field of the parent page to generate the name. Only the generation from date function is possible now. Try it out!
But with my solution you could use all the parent page fields + date + some string in the order you want it. This is obviously more + inclusion what we have.

About title:
Now you get, whatever you defined in the setting the title 'untitled' or a title generated from date which you maybe want to overwrite anyway! No other possibilities until now!

Maybe I understoud you completely wrong, or you my solution. :rolleyes:  Have a look in github.

  • Like 2

Share this post


Link to post
Share on other sites

did this ever get merged?  In 2.6.1,  something as simple as title_Y/m/d looks like it ends up being interpreted according to php date().

Share this post


Link to post
Share on other sites

Since there are a lot of topics about the same theme, I decided to write a small module which overwrites the core function ___SetupPageName().
The module allows now to populate the page name

  1. using proprietary date() function. Works like PHP date() with follwing exceptions: 
    Everything between the brackets is detected as format string, meaning no 2nd parameter possible. No need to use quotes around the format string. Spaces not allowed.
  2. from any page property, page field including subfields, parent property, parent field etc. Meaning everything what you get with $page->get(); including dot syntax.

The function will give error and warnings in case of unproper settings, but creates the page with name 'untitled' anyway.

Download here: http://modules.processwire.com/modules/process-setup-page-name/
Some Examples
The following settings in parent template 'Name Format Children' will

assign name immediately.

  • date(Y)
  • date('Y-m-d')
  • parent.title
  • parent.parent.title
  • parent.id
  • template.id

assign name after page saving and/or population of depending field. Overwrites 'untitled' after all fields which are defined in parent template are populated.

  • id (any other page property)
  • pagefieldname, multiple pagefieldnames

show a warning.

  • pagefieldname (value not populated)

show an error.

  • date() // empty, no format assigned
  • date(Y // missing closing bracket
  • date(Y md) // unallowed space
  • notexistingfieldname
  • notexistingproperty
  • existingfield.notexistingsubfield

The function in the module  ___SetupPageName() could be completely copied as is to the core class $pages.

@Ryan
Would be nice to see this in core. :)

Related topics:

https://processwire.com/api/modules/process-template/

Any recommandations after testing welcome. Download here:

Download here: http://modules.processwire.com/modules/process-setup-page-name/

Edit: small enhancement to prevent display of warning twice.
23.12.15 multiple values possible now
24.12.15 made compatible with PW 3.x
27.12.15 Update Version 1.0.8
09.01.16 Update Version 1.1.0

Edited by kixe
  • Like 16

Share this post


Link to post
Share on other sites

From now you can use multiple values separated by space. Example: "parent.title date(Y) myfield". Page name will remain 'untitled' until last required field is populated.
You will get informed about this by a warning.

Merry Christmas.

  • Like 3

Share this post


Link to post
Share on other sites

Hey kixe,

Thank you - this is awesome and solves one of my biggest issues with PageTable fields - getting meaningful page names without the possibility of conflicting names which I don't think the user should ever have to consider.

One minor thing (but critical) - when installing with PW 3.x I get this error:

Catchable fatal error: Argument 1 passed to ProcessWire\Pages::__construct() must be an instance of ProcessWire\ProcessWire, none given, called in /wire/core/Modules.php on line 481 and defined in /wire/core/Pages.php on line 128

It is easily fixed by adding an empty construct method to your module, like this:

public function __construct() {
    // intentionally empty
}

I am definitely looking forward to using this with all my PageTable fields!

  • Like 2

Share this post


Link to post
Share on other sites

Could you also add the new notes to the PageTable Automatic Page Name Format section on the Input tab?

Share this post


Link to post
Share on other sites

Hello, 

Ive just installed this module but get the following error. Any Ideas?

Error: Call to undefined function _() (line 56 of F:\Programs\wamp\www\tml\site\modules\ProcessSetupPageName\ProcessSetupPageName.module) 

This error message was shown because you are logged in as a Superuser. Error has been logged.
  • Like 1

Share this post


Link to post
Share on other sites

@Jon
Thanks for reporting. I fixed this. Please update to 1.0.9

  • Like 1

Share this post


Link to post
Share on other sites

hi kixe,

thank you for your work, i can use this in my current project :)

but i found two bugs:

  • date('d.m.Y H:i:s') forename surname
    gives an error due to the space in date()
  • date('dmY',created) forename surname
    07012016-2016-01-07t22-23-12-01-00thu-07-jan-2016-22-23-12-0100europe-viennapm31europe-vienna07-test-test

i don't need date('Ymd',val), but just tried it and think it would be good to handle this one as well. didn't look at your code but i think the regex should get some fine tuning :)

Share this post


Link to post
Share on other sites

Hi Bernhard,
thanks for the effort you have made testing my module. I think my regex is ok. Maybe I have to modify the detection of multiple fields, which happens before. For now it is a single space character. Since spaces are not allowed in page names you don't need to use spaces in the date function this will be anyway translated later (space -> dash).

Does it make sense to provide a timestamp from a page property or datetime field, since you could handle this in another way?
It
s a bit painful to use the date() function, contrary to the correct PHP syntax
. Meaning I didn't define any timestamp constants like 'val' or 'created' in the module. To prevent confusion I want to stay using correct date() syntax.

For your second example you can easily use: "created forename surname" and you will get the same result.

I don't understand date('dmY',val). If val is a pagefield, which returns a timestamp please use: 'val forename username' after configuring the output of field 'val' to 'dmY' in the field settings.
If you then need other output formats in the templates you can do:

echo date('Y-m-d h:i',$page->getUnformatted('val'));

Share this post


Link to post
Share on other sites

hi kixe,

sorry - i was unclear.

"think it would be good to handle this one as well" was meant as "would be good to handle this as a wrong input" and maybe give an appropriate error message that helps the user find a correct string. "val" was just a placeholder for any value. as i said i don't need this because i switched to standard name for children + creating title field on page save per custom module.

i agree that there is room for improvement in the core at this special step of naming children automatically :)

Share this post


Link to post
Share on other sites

I dont know if this is a problem of the module or from PW in general.

The path names on a multilingual site are only changed for the default language and not for the other languages. In my case I use parent title and date. In German (default) it shows me both, but in English I only get the parent title without the date.

Best regards

It is not a big problem because you can change the pathname afterwards via a hook for the other languages.

Edited by Juergen

Share this post


Link to post
Share on other sites

@Juergen
Thanks for reporting this. If I find a little time I will have a deeper look. Multilanguage support isn't tested very well until now.

There are still some other situations where the module doesn't work:

  • If you want to generate name from a file field (selector like 'myimagefield.description') you will get an error.
  • Name generation from a ProfieldsTable column is also not possible.

I agree multilanguage name generation should be supported.

Share this post


Link to post
Share on other sites

You can do it in the module. Here is the code of an module which changes the path names for multilingual site.

<?php
/**
 * 
 * ProcessWire 2.x 
 * Copyright (C) 2014 by Ryan Cramer 
 * Licensed under GNU/GPL v2, see LICENSE.TXT
 * 
 * http://processwire.com
 *
 */
class CorrectPagenames extends WireData implements Module
{
    public static function getModuleInfo()
    {
        return array(
            'title' => 'CorrectPagenames',
            'version' => 1,
            'summary' => 'Output custom path names multilingual',
            'singular' => true, // Limit the module to a single instance
            'autoload' => true // Load the module with every call to ProcessWire 
        );
    }
    public function init()
    {
        // init() is called when the module is loaded.
        // saveReady is a hook after processing the previous changes of the page,
        // but just before those changes are saved to the database.
        // It's called for each page that's being saved, no matter if it's in
        // the backend or in your templates via the api.

        $this->addHookBefore('Pages::saveReady', $this, 'beforeSaveReady');
    }

    public function beforeSaveReady($event)
    {
        $page = $event->arguments[0];
        //create custom path name for children events
            $datestart  = $page->publish_from;  // I use the publish from date for the path name
            $datestart  = date('Y-m-d', $datestart);
            $eventtitle = $page->parent->title; // I also use the parent title for the path name
            $page->name = $eventtitle . '-' . $datestart; //putting it all together for the default language
            foreach ($this->languages as $lang) { //multilanguage starts here
                if ($lang->isDefault())
                    continue;
                $lname               = $lang->id;
                $pageName            = $page->title->getLanguageValue($lang);
                $pageName            = $pageName . '-' . $datestart;// create custom path for other languages
                $pagelanguage        = "name" . $lang;
                $page->$pagelanguage = $pageName; //this sets the path name for each language 
            }
     
    }
}

You can take a look on how to achive it (as an inspiration ;) )

Best regards

  • Like 2

Share this post


Link to post
Share on other sites

Hi,

I have install this module on PW 3.0.12 and when I try to edit a template, this error popup..​

Fatal error: Using $this when not in object context in /site/modules/ProcessSetupPageName-master/ProcessSetupPageName.module on line 68

Do you have any idea why I have this error?

Thank you

  • Like 1

Share this post


Link to post
Share on other sites

@Filkaboy
Thanks for reporting. I fixed this.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
    • By ukyo
      FieldtypeFontIconPicker
      Supported Icon Libraries
      FontAwesome 4.7.0 Uikit 3.0.34 IonicIcons 2.0.1 Cahangelog
      NOTE: Module store data without prefix, you need to add "prefix" when you want to show your icon on front-end, because some of front-end frameworks using font-awesome with different "prefix".
      Module will search site/modules/**/configs/IconPicker.*.php and site/templates/IconPicker.*.php paths for FieldtypeFontIconPicker config files.
      All config files need to return a PHP ARRAY like examples.
      Example config file : create your own icon set.
      File location is site/configs/IconPicker.example.php
      <?php namespace ProcessWire; /** * IconPicker : Custom Icons */ return [ "name" => "my-custom-icons", "title" => "My Custom Icon Set", "version" => "1.0.0", "styles" => array( wire("config")->urls->templates . "dist/css/my-custom-icons.css" ), "scripts" => array( wire("config")->urls->templates . "dist/js/my-custom-icons.js" ), "categorized" => true, "attributes" => array(), "icons" => array( "brand-icons" => array( "title" => "Brand Icons", "icons" => array( "google", "facebook", "twitter", "instagram" ) ), "flag-icons" => array( "title" => "Flag Icons", "icons" => array( "tr", "gb", "us", "it", "de", "nl", "fr" ) ) ) ]; Example config file : use existing and extend it.
      File location is site/configs/IconPicker.altivebir.php
      <?php namespace ProcessWire; /** * IconPicker : Existing & Extend */ $resource = include wire("config")->paths->siteModules . "FieldtypeFontIconPicker/configs/IconPicker.uikit.php"; $url = wire("config")->urls->templates . "dist"; $resource["scripts"] = array_merge($resource["scripts"], ["{$url}/js/Altivebir.Icon.min.js"]); $resource["icons"]["flag-icons"] = [ "title" => "Flag Icons", "icons" => array("tr", "en", "fr", "us", "it", "de") ]; $resource["icons"]["brand-icons"]["icons"] = array_merge($resource["icons"]["brand-icons"]["icons"], array( "altivebir" )); return $resource; After you add your custom config file, you will see your config file on library select box. Library Title (Location Folder Name).

      If your library categorized and if you have categorized icons set like uikit and fontawesome libraries, you will have category limitation options per icon field or leave it empty for allow all categories (default).

      Example : output
      if ($icon = $page->get("iconField")) { echo "<i class='prefix-{$icon}' />"; } MarkupFontIconPicker Usage
      // MarkupFontIconPicker::render(YourIconField=string, Options=array) echo MarkupFontIconPicker::render($page->YourIconField, [ 'prefix' => 'uk-icon-', // Icon class prefix, if you have different prefix, default is : "fa fa-" 'tag' => 'span', // Icon tag default is : "i" 'class' => 'fa-lg', // If you have extra cutom classes, for example : icons sizes, Array or Sting value 'style' => 'your custom styles if you have' // Array or String Value ]); Theme support

      Search support

      Category support

       
×
×
  • Create New...