Search the Community
Showing results for tags 'tips'.
-
Hey there! I posted this before I took advantage of a feature in RockPageBuilder to manage globally sharable settings for blocks in RPB. @bernhard has since added some very nice features that make my tips below a little out of date. I recommend viewing his comment below and taking advantage of RPB's new native solution. Thanks to Bernhard for his ongoing work of making RPB event better for developers and users 👏 ---------- Sharing a strategy that I have found useful when working with blocks and block settings. I use the block settings feature heavily and in many instances most blocks have some of the same settings fields. To help make managing these easier, I created a workflow to help me manage these and it's saved me a good amount of time while being able to reuse settings between projects very easily. In my case, some of these are: Spacing between blocks/sections on the page Background/accent colors Content location within blocks Block presentation My approach is to create a dedicated class with static methods that return a settings array. Example: <?php // /site/init.php /** * This creates a namespace for a /site/templates/RockPageBuilderSupport directory */ wire('classLoader')->addNamespace('RockPageBuilderSupport', __DIR__ . '/templates/RockPageBuilderSupport'); This file contains the fast helper methods that create settings fields <?php // /site/templates/RockPgeBuilderSupport/BlockSettings.php namespace RockPageBuilderSupport; use ProcessWire\RockFieldsField; /** * Reusable block settings */ class BlockSettings { public static function sectionPresentation( RockFieldsField $field, array $config = [], array $additionalValues = [], ): array { $name = 'section_presentation'; return [ 'name' => $name, 'label' => 'Section Presentation', 'value' => $field->input($name, 'select', [ '*normal' => 'Normal', 'standalone' => 'Standalone', 'standalone_drop_shadow' => 'Standalone + Drop Shadow', ...$additionalValues, ]), ...$config, ]; } public static function bodyWidth( RockFieldsField $field, array $config = [], array $additionalValues = [], ): array { $name = 'body_width'; return [ 'name' => $name, 'label' => 'Body Width', 'value' => $field->input($name, 'select', [ '*constrained' => 'Constrained', 'full' => 'Full', ...$additionalValues, ]), ...$config, ]; } public static function backgroundColor( RockFieldsField $field, array $config = [], array $additionalValues = [], ): array { $name = 'background_color'; return [ 'name' => $name, 'label' => 'Background Color', 'value' => $field->input($name, 'select', [ '*white' => 'White', 'seafoam' => 'Seafoam', 'champagne' => 'Champagne', 'none' => 'None', ...$additionalValues, ]), ...$config, ]; } // ...as many commonly used settings methods as you need } Settings are easily reusable in any block. <?php declare(strict_types=1); namespace RockPageBuilderBlock; use ProcessWire\RockFieldsField; use RockPageBuilder\{Block, BlockSettingsArray}; use RockPageBuilderSupport\BlockSettings; class BlogFeed extends Block { const prefix = "rpb_blogfeed_"; /** * Block config info */ public function info(): array { return [ 'title' => 'News Article Feed', 'description' => 'An array of blog posts', // ...other info ]; } /** * Runtime block settings */ public function settingsTable(RockFieldsField $field): BlockSettingsArray { $settings = $this->getDefaultSettings($field); $settings->add( BlockSettings::bodyWidth($field) ); $settings->add( BlockSettings::bodyLocationVertical($field) ); $settings->add( BlockSettings::actionLocationVertical($field, config: [ 'label' => "Below 'view all' link" ]) ); $settings->add( BlockSettings::sectionPresentation($field, additionalValues: [ 'full' => 'Full news feed design', ]) ); return $settings; } // ... ommitted for brevity } This has helped me easily manage common settings for 20 different blocks by editing the settings in one place. By adding the $config and $additionalValues parameters to the BlockSettings methods, overrides can be added when individual blocks need customization. Thanks to the runtime nature of block settings, making these changes on the fly is extremely easy. This has saved me a lot of time and helps keep things organized. I was able to carry over the bulk of my work with settings from one project to another and it really helped out a lot. Would love to hear if others out there have developed some tips and tricks that help you build your sites!
-
I as have been a bit confused for some time about how the "Markup Regions" functionality in Processwire worked. But i have know read a bit more and think that i am getting to grips with it. And Markup Regions is going to be huge. To aid me in understanding Markup Regions better i started to read the Source code for the new "Regular" theme in conjunction with the Blog about the markup regions. It helped me a great deal to understand the basics and more fine details of it. A tip is to open both links and use the Source code of the "Regular" theme while reading the blog post. The Source code: https://github.com/processwire/processwire/blob/dev/site-regular/templates/_main.php The Blog post: https://processwire.com/blog/posts/processwire-3.0.62-and-more-on-markup-regions/ Markup Regions in ProcessWire (New - 2022-09-08) https://processwire.com/docs/front-end/output/markup-regions/ I hope this could help others starting out with markup regions. Just take it slow and read it a couple a times and soon you will see the greatness of markup regions. /EyeDentify
-
Here is the scenario. You have developed a blog or news site or blog section to your site and you have created a basic tag system using a Page Reference field. How can you add related articles easily? This is one way by using Hanna code. I like this method because it gives me the choice of showing or not showing related articles and choosing the tag. My articles use a template called basic-page which includes a Page Reference field called tags. This is a multiple select field. I have created a Hanna code called "tagsearch" and given it the attribute "tag". In my textarea field it is used thus: [[tagsearch tag="fish"]] The Hanna code simply searches the title field of the tags pages for the single term and returns the pages that have that tag. I have limited the results to 8. From the results, we pluck the title field of the pages, the small image that I use for my thumbnail, and the url. However, we do not want to also return the page we are displaying, so we simply eliminate it by making sure that that none of the results have the same page name. Here is the commented Hanna code. <?php // Find the pages that use the specified tag $articles = $pages->find("template=basic-page, tags.title=$tag, limit=8"); // Start the loop foreach($articles as $article){ // Check we are only displaying articles that are NOT the current page if($article->name != $page->name){ // Add a thumbnail, but check it is there so we don't get errors if($article->image_small){ echo "<a href='{$article->url}'><img src='{$article->image_small->url}'></a><br>"; } // Grab the article title echo "<br><a href='{$article->url}'>{$article->title}</a>"; // end the check to make sure we do not show the current page } // end the loop } And that is it.
-
Hello Fellow forum members. I wanted to share two links to a guide and a cheatsheet concerning Crontab and Cronjobs. This is a result of me doing some research in how Cronjobs work and how to use it and i thought i share for other beginners use. So the guide that got me started and is a good reference is: A Comprehensive Crash Course Into Cronjobs (sitepoint) And also i found this sort of cheatsheet and database of cronjob configurations handy: Corntab - the Crontab GUI I hope these tips can help any beginners like myself get up and running with cronjobs.
-
Was just wondering what time-saving tips you guys have from one project to the next. Are there things you carry over? Every time you add a contact form do you code it from scratch? Or do you go to another local project and copy and paste code over? I'm just conscious that though the main reason I love PW is that I code it all myself, line by line, it also means I probably end up spending too much time in the nitty gritty. So do you have any time saving tips? Am also interested in your workflows within the admin section (think I've asked this before). Is there anything in particular you've learned that helps you get your PW projects up and running faster? Cheers!