Jump to content

TomPich

Members
  • Posts

    58
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by TomPich

  1. Hi guys,

    I might have an interesting project in the coming months. For now, I have to give a quote for this job.
    The project is a website where different kinds of users could post ads about pets for adoption or for sell.
    This means that I must be able to handle hundreds of users with an account (three different kind of accounts : private, association and animal professionals) and hundreds, maybe thousands of pets.

    My first thought is : PW + AlpineJS. I read that PW is capable of handlings hundreds of thousands of pages. I begin now to be quite familiar with PW API, and AlpineJS would let me bring some interactivity.

    My second thought : PW headless, acting as a REST API provider, and Svelte for the front end (I never used Svelte, but it seems nice and quite light weighted, it would be an occasion to learn on a real project – I learned a little bit of React but never had the occasion to use it for real projects). I’m afraid Svelte would be a bit of an overkill, I don’t really need advanced reactivity and all that. But it could be a way to broaden my horizons.

    My third thought : Laravel for backend (never used it – I’m a bit familiar with Symfony, but Laravel seems more light weighted). The publishing needs are not big : create an account, publish a pet file. And that’s it. So maybe (maybe !) a PHP framework would go straight to the point. I could even develop it from scratch, but I don’t trust myself 100% about security.

    What would be your choice ?

    Any clue about the time you would need to do that ? My guess is about 80-100 h for the first solution.

    I am very eager to hear some experienced guys' opinions...

    Thanks in advance.

    • Like 1
  2. Hello @Neue Rituale,

    I’m exploring your module possibilities. It seems very useful.
    I can’t figure out something though. I’m sure it’s very simple.
    Let say I have a ptn field in my homepage. I defined a template (named "section") to be used with this ptn field as an element.

    In the php template file of this section, how can I display the section title ? If I write $page->title, I get "Home" (so the title of the page where the ptn field lives), instead of the section title itself.
    Said in another way, the $page variable is not scoped to the element template. It’s always scoped to the page template. So how can I catch the field value of the element templates?

    Any help would be greatly appreciated.

    Thanks
     

    PS: for custom CSS, it seems that, because of the shadow DOM, the CSS custom properties like --bg-color scooped in the root of the page are not defined when used in the shadow DOM.

  3. Woaw... Even simplier ! I didn’t know about the Page::changed hook. 😊

    Thanks Bernhard.

    EDIT: I just realized that, in my use case, it wouldn’t be enough. I don’t want to execute the logic if the field has changed, but [IF the field has changes AND the new field value is true]. But still, this hook is great and may cover 90% of use cases.

    • Like 1
  4. Even if you enter that manually :

    "sameAs" : [
                "https://www.facebook.com/company",
                "https://www.instagram.com/company",
                "https://www.linkedin.com/company"
            ]

    the browser still skips the line breaks (as shown in the console).  I guess you can’t override this behaviour.

    • Like 1
  5. I recently had the following need :
    For pages of a given template (named
    page-post-operation), I had to check if a certain field value had changed (a checkbox field named postReadyForPublish) and execute some logic if that was the case (in my case, send an e-mail to an admin user with proper rights to publish it).

    I thought, at the beginning, that it would be a little bit tricky as I needed to compare the value of this field for the previous version and the new version of the page.
    And it actually was not tricky. Kind of... 😊

    So this is the hook I put at the beginning of the /site/templates/admin.php file (as it’s only useful in the admin part).

    $wire->addHookBefore("Pages::saveReady(template=page-post-operation)", function($event) {
    	$page = $event->arguments(0);
    	$oldPage = $this->pages->getFresh($page->id); // this is the tricky part
    	if( $page->postReadyForPublish && !$oldPage->postReadyForPublish ){
    		// logic goes here
    	}
    });

    When you retrieve the previous version of the page in the DB, make sure you use the getFresh method. Otherwise, you will get the date in the cached version of the page, which are immediately saved, meaning that $oldPage and $page would have the same field values.

    Hope this may be useful to somebody else.

    • Like 4
  6. Hi guys,

    I think what I try to achieve is quite simple, nevertheless I can’t find out how to do it.

    On a specific template, I’d like to add some general description about the whole template.
    It’s just some text that I’d like to insert at the beginning of the admin page when a page based on this template is edited.
    I don’t need to create a whole new custom admin page.
    Any clue?

    Thanks

  7. Hey howdytom,

    I’m not sure I fully got your need, but for what I understood (i.e. use the same image in multiple places), I would create a page called media, and add a multiple images field – with maybe a specific text field added to each image, called for instance "role". I would put all the images I use repeatedly here.

    I can then call these images anywhere on the front (and in TinyMCE). The role field would allow me to easily filter the images I need.

    • Like 1
  8. Hello guys,

    I’d like to dig a little bit in the $cache API.
    In my homepage template, I call data from on other page, in repeater field.
    Although it has only 16 items, I noticed that it slowed down the loading process.
    When I use the cache a template level, the page is definitely faster.
    In the homepage template, I do the following :
     

    $consultants = $pages->get(1027)->repeaterConsultants;
    foreach ($consultants as $consultant) {
        // do stuff with $consultant->consultantPortrait, $consultant->consultantName, etc...
    }

    I tried to put in cache the $consultants variable. I read a tutorial on processwire.dev and I read the docs but I can’t get it working...
    The test below work perfectly though.

    $test = $cache->get("test", 3600, function(){return "this is a test";});
    var_dump($test);

    So how could I cache the $consultants variable?

    Thanks.

  9. Hello all,

    For my current project, each page have an image called thumbnail used for various purposes. If the thumbnail is not provided, I have a fallback image.
    So on almost each PHP template, I have the following code at the beginning:

    $thumbnailUrl = $page->pageThumbnail ? $page->pageThumbnail->size(1920, 400, ["crop" => "center"])->webp->url : $pages->get(1039)->configDefaultImage->url ;

    To avoid repeating that on each page PHP template, what can I do to generate, for each page, something like $page->thumbnailUrl automatically? Do I have to use a hook ?

    Thanks guys for your help

    Cheers

    Thomas

  10. I received so much help from kind people on this forum; it’s now my turn to contribute. 😊
    I recently had a need for a customer. They have a long list of articles, and they wanted to find any article corresponding to some criteria. They could use the Pages > find tool, which use pageLister, but then they would have to each time select some filters, which can be quite intimidating when you have many fields.
    So my idea was to create an admin page with the right filters already set. The customer only needs to use some of them. As I found out, this is much simpler than I first thought. So my tutorial is not rocket science, but my hope is that it helps newbies like me to achieve this... 😊

    So first, you need to create a simple custom admin page. Bernhard already made a nice tutorial about this, and it’s quite straightforward (like everything in PW ❤️).

    Here is the code to create this custom admin page in our situation (thanks to Bernhard) :

    namespace ProcessWire;
    
    class ProcessArticlesList extends Process
    {
    
    	// Infos about your module and some settings
    	public static function getModuleinfo()
    	{
    		return [
    			'title' => 'Articles Admin Page',
    			'summary' => 'No need to be afraid of building custom admin pages. ;-)',
    			'author' => 'Your name goes here',
    			'version' => 1,
    
    			// you can set permissions here
    			'permission' => 'meeting-view',
    			'permissions' => [
                    'meeting-view' => 'View Meetings page',
                ],
    
    			// page that you want created to execute this module
    			'page' => [
    				// your page will be online at /processwire/articles/
    				'name' => 'articles',
    				// page title for this admin-page
    				'title' => 'Articles',
    			],
    		];
    	}
    
    	public function ___execute()
    	{
    		// the logic goes here
    	}
    
    }

    So, with this code, you get a new module that will produce a blank page. You have now to create a ProcessArticlesList folder inside that file in the site/modules folder and put your new file inside.
    Then, activate your module.

    The ___execute() method will run on page load. It’s supposed to return a string which will be your page content. Now things get quite... simple! 😄
    The idea is to run an instance of ProcessPageLister, with custom parameters. You can find all these parameters in /wire/modules/Process/ProcessPageLister/ProcessPageLister.module (there are comments that really help you) and you can also have a look at the API doc about ProcessPageLister.
    Here is an example that covered my needs :

    public function ___execute()
    {
    	// this is to avoid error detection in your IDE
    	/** @var \ProcessPageLister $lister */
    
    	// get the module, so that you can use it the way you want.
    	$lister = $this->modules->get("ProcessPageLister");
    
    	// from here, the comments in the source file were self explanatory, so I found how to cover my needs
    
    	// filter all pages with the "meeting" template. This filter is by default, won’t show
    	// in the filter list and cannot be changed.
    	$lister->set('initSelector', "template=meeting");
    
    	// Then I set 3 filters, left blank, so that the user has just to fill them – or leave them blank
    	$lister->set('defaultSelector', "title%=, themes.title%=, text%=");
    
    	// Disallow bookmark creation. In my use case, there was no sense for that.
    	$lister->set('allowBookmarks', false);
    
    	// let the table be full width
    	$lister->set('responsiveTable', false);
    
    	// use the custom order defined by the user by moving the pages in the page tree
    	$lister->set('defaultSort', 'sort');
    
    	// and just show the configured filter on the page.
    	return $lister->execute(); 
    }

    As you can see, there are 7 lines of specific code to achieve that. How elegant! 🥰

    Hope that it is helpful to someone somehow.

    Cheers
    Thomas

    • Like 7
    • Thanks 3
  11. Hi folks,

    When you use page lister and select filters, is there a way to specify a OR for some filters? Something like "Title contains text like my_word" OR "Body contains text like my_word"?

    I’m pretty sure I saw a checkbox to specify some OR conditions recently (I think it was in the BatchChildEditor), but I can’t find it any more. Couldn’t find any clue on the forum.

    Thank you guys for enlighting me.
    Cheers

  12. Hi folks,
    My research about hiding pages in the page tree led me to this thread.
    In the ProcessPageList module, there is a "Hide these pages in page list(s)" section where you can "select one or more pages that you do not want to appear in page list(s)."
    However, when I select a page, it’s still visible in the page tree. Is it normal? In which situation these pages would be hidden? I don’t get that.
    As always, thanks a lot.

  13. Hey there,

    I’ve been playing around with BCE. I love all its functionalities and will need it for a project very soon.

    A quick question though : when in lister mode, you can define filters, and that’s great. But I could not find how to predefine blank filter. Imagine that my client will frequently use a filter on a field called "place". How can I get this filter ready to be filled, like "Place" + "contains texte like" + _blank_ ? Otherwise, he will always have to pick the right field and the right matching condition each time he lands on the page.
    And BTW, is there any way to hide the filter "Parents" "equals" "id" ? Because this is implicit and my cause confusion to my client.

    Many thanks in advance 😊

  14. @d'Hinnisdaël Thank you.

    I’ll explore your suggestions. I’m not sure what you mean by "configuring a separate admin Lister page with filters". But it sounds like being quite straight forward.

    For now, I’ve been building a custom panel following your documentation. Seems a lot of work. I’m getting somewhere, but I’d rather respect the spirit of your module and and choose a more clever solution to achieve my goal.

    • Like 1
  15. Hey there,

    Still playing around with this awesome module. One question : is there a way to collect user input to customize the display of a collection? Here is an example.

    I have a template called “meeting” with 200 instances. I’d like to create a collection panel on the Dashboard, where the user can filter the result according to some simple entries fields : place (a simple text input) and themes (a multiple pages input). The way I see things : if the user does not filter, we have a paginated list of all the meeting pages (so up to this point, I did it). Somewhere in the panel wrapper, I have a text input where the user can specify a place. And another input (like select) where the user can choose a theme. Once done, the collection is filtered accordingly.

    Does dashboard have a way to do that (I didn’t find) ? Or do I need to create a custom admin page?
    Thank you guys!

  16. 1 minute ago, d'Hinnisdaël said:

    @TomPich If the "date" field is an actual date field type (as opposed to an integer field storing the raw timestamp), this should work out of the box. The module knows about date fields and how to format them with using a custom format. If you're storing the timestamp as an integer, I'd suggest switching to an actual date field and getting the raw timestamp from that date field in the frontend instead: $page->getUnformatted('date') will usually get you the non-formatted timestamp as integer.

    Thanks @d'Hinnisdaël. I was editing my post because I found the solution. The value is stored as an actual date field type. As I need to get the date in french, using IntlDateFormatter, I have to store them as timestamp (I don’t want to install the whole traduction pack just for twelve months... 😅). See the --- edit--- part of my last post.

×
×
  • Create New...