Recommended Posts

While there was a lot of people asking how to make navigation, and there were many examples around already (apeisa, ryan...) I took the chance to sit down 2-3 hours to make a simple navigation module. It has even some options you can control some aspects of the output.

Installation:

1. Put this module's folder "MarkupSimpleNavigation" into your /site/modules folder.2. Go to your module Install page and click "Check for new modules". It will appear under the section Markup. Click "install" button. Done.

Technically you don't even need to install it, after the first load call ( $modules->get("MarkupSimpleNavigation") ) it will install automaticly on first request if it isn't already. But it feels better. However, it will not be "autoloaded" by Processwire unless you load it in one of your php templates.

Share this post

Link to post

Share on other sites

The only thing I wonder is why make it an autoload module? This is one that is meant for on-demand use, so it doesn't technically need to be an autoload module. Though I agree it does make for a nicer API call:

Share this post

Link to post

Share on other sites

I just implemented a new option to prepend the rootpage to the navigation.

echo $treeMenu->render( array('show_root' => true) );

Thanks Ryan! Yes I wasn't sure if that makes sense, now as you're saying it... So could I make it so that it isn't autoload and load it once before the call, and then you would have the $treeMenu->render variable? Like

Share this post

Link to post

Share on other sites

This is off-topic really but as a newb to PW (and github), my desktop github client shows the github version is now updated, I just looked in the forum but couldn't find a post to tell me the preferred method for updating a module.

Is it a case of just getting the latest version and overwriting the contents of the folder the module is in locally? Or doI need to disable the module first? Or something different?

Thanks for any help, cheers, -Alan

Share this post

Link to post

Share on other sites

This is off-topic really but as a newb to PW (and github), my desktop github client shows the github version is now updated, I just looked in the forum but couldn't find a post to tell me the preferred method for updating a module.

Is it a case of just getting the latest version and overwriting the contents of the folder the module is in locally? Or doI need to disable the module first? Or something different?

Thanks for any help, cheers, -Alan

You are save to just replace the files. No need to uninstall, as it doesn't install something or depend on something.

Although because it was at first "autoload" and I changed that, you should check in the db table "modules" if the col "flags" of this module is set to 1 and not 3. If it's at 3 it you can just change it manually to 1.

Share this post

Link to post

Share on other sites

You are safe to just replace the files. No need to uninstall, as it doesn't install something or depend on something.

Although because it was at first "autoload" and I changed that, you should check in the db table "modules" if the col "flags" of this module is set to 1 and not 3. If it's at 3 it you can just change it manually to 1.

Share this post

Link to post

Share on other sites

... I just adapted (don't really know PHP to do it on my own!) a script for multilevel navigation and this comes out!!! At least I learnt a few things about PW whilst doing that!

It's great that people are coming with modules like this, but the reason PW is so flexible, is because it's so easy to build your own snippets of code to achieve this kind of things. I have mixed feelings concerning the modules, and tend to prefer the idea of the snippets repository...

The $exclusions is an array that contains the name of the template of a page which we don't want to see its children. For example if we have a 'News' page with a template of 'news-list' that aggregates a list of article pages with template 'news-article', then 'news-list' should be added in the $exclusions array. I hope that's clear. Not sure if this is the most flexible way to do this, but it works for me right now and I'm sure someone will come along and improve on it!!

One other change was that I removed the newlines from the <li>'s to make the menu code easier to read and also I've changed the $childs to $children just because it bugged me... sorry!!

I haven't tested the module extensively (read: at all) and as I mentioned in a previous post I'm not really a PHP coder (or a web dev for that matter!) so bear that in mind when you read the few lines that I changed!!!

Share this post

Link to post

Share on other sites

- That's a good addition to exclude page per template, it can make sense in the example with news pages. I will implement it as an option.

- Hehe, yes I'm not native english speaker, so I often use false words like "childs" instead of children. Thanks for pointing out.

- Your right the markup outputted could be improved, but I mostly use a web inspector anyway so that it wouldn't matter much.

- I'm not sure if I think about it, last and first is something that can be done more easy with css using li:first-child, li:last-child. And if implemented I would see it as turn on/off feature like the levels-. I don't want that outputted by default.

EDIT: Thinking about setting classes, I thought it way could make sense to have an option for where to put the item classes, either <a> or <li>.

EDIT: Oh and I would be good to may use github "fork" to then make a pull request so I could implement or merge additions. Or even easier, make a feature request. Same with bugs. It would help not having multiple version around, as people start copying your code and would may lose it after updating it with the github version.

Share this post

Link to post

Share on other sites

I made an update to the module. If you get the latest version you'll get new features.

Added support for custom selector:

Instead of adding more options to exclude pages, since PW is so open as to how to set up you pages/template stucture, I've implemented the option to specify a PW selector. So some of the power of it comes into play. (Remember it's always best-practice to sanitize values that may come from user input you can trust. This module doesn't do any)

You can for example hide page(s) with a certain or parent(s):

echo $tree->render( array("selector" => "parent!=1008|1002") );

And child pages from those parent will not be rendered.

Or if you want to exclude page(s) with certain template(s) you would do :

Share this post

Link to post

Share on other sites

I am new to PW and just checking out the possibilities by reading hours in the forums before getting my hands dirty ;-) The navigation was on the schedule today and I like your module (also coming from MODX and looking for a wayfinder replacement). Your module seems to do more or less exactly what one needs for a navigation. But one (or two) suggestions: I would like to be able to define the output myself, because habits or requirements are different. Sometimes I need an additonal <span> somewhere or would like to use another field as title (or well, a title at all ;-) ) and so on. Since PW doesn't use any template or placeholder syntax I am not sure how to do so without hacking your module. Antoher example: the active class should be appended to the <li> element since this is the element which is active, not a child of it. I often need to style the <li> element and the containing <a> element as well. I your markup this is hard to accomplish, other way around it would be easy (you already mentioned an upcoming option for that). But as I said, requirements differ all the time and the most flexible solution would be to define the markup myself (or falling back to the standard output of course).

Thank you for your solution(s), I will try PW on a "real" project soon.

Share this post

Link to post

Share on other sites

Hi MadeMyDay - you might be better off just taking a look a the default head.inc template and changing the breadcrumb layout there if you want to do something quite a bit different.

I know how useful WayFinder was coming from MODx myself, but familiarising myself with the head.inc template file also helped me to learn the basics and I was off into the advanced stuff in no time.

That's not to knock Soma's module by any means as it's a good, quick way of getting navigation up and running quickly, but rather saying that PW is really easy to customise to do what you want with a fairly easy learning curve compared to full-blown PHP development.

Share this post

Link to post

Share on other sites

Hey MadeMyDay! Thanks for your post and inputs. As a modx user myself (not anymore) I certainly know Wayfinder, but found it a little too overhelming with way too many complicated options, so I've never used it to it's full power, also because the basic output was always enough.

Pete is right, if you want the ultimate flexiblity you would want to create your own nested function to output.

But I guess it also can get complicated depending on what you want to do. Generating a basic nested navigation is really easy using PW API, but I like to have some sort of tool that suites for most cases without getting into too much coding everytime. So having a module like I see as a nice way you can always rely on for fast implementation.

You're right that maybe best option would be to have classes appended to <li> element and not inner item. It will more easily allow for if you are styling <li> elements, but let's you as well style the inner element. The other way around it isn't possible. I'm always styling the anchor and not the list element as it is the most easy and reliable cross-browsers. That's why I implemented it this way. But it's now changed by default.

I understand that having a possibility to define custom markup will make it even more flexible and I was already planing to do anyway. Though with such implementation it's always the case that at some point you're still limited at best in some way or the other.

I already looked into it and found a easy implementation that will work and not having too much options. I just commited a major new update to github and updated first post to reflect changes. It let's you now define custom markup even with placeholders/tags for fields you want to output.

I also renamed and removed some options with this update, so if you already using it, make sure you update your template code. Sorry for the inconvenience it may cause. But I think it is now better and will not change in future.

Changed:

'class_current' to 'current_class'

'class_parent' to 'parent_class'

'css_levels_on' to 'levels'

'css_firstlast_on' to 'firstlast'

Added:

'has_children_class' => 'has_children'

'levels_prefix' => 'level-'

'outer_tpl' => '<ul>||</ul>'

'inner_tpl' => '<ul>||</ul>'

'list_tpl' => '<li%s>||</li>'

'item_tpl' => '<a href="{url}">{title}</a>'

'item_current_tpl' => '<a href="{url}">{title}</a>'

Removed:

'ul_class' and 'ul_id'. Which now can be added via 'outer_tpl'.

While at it I also fixed a max level issue when using other root page than "/".

Thanks.

Share this post

Link to post

Share on other sites

yes, I already took at the head.inc template and the (one level) navigation is straightforward. But if dealing with more levels it gets a bit more complicated. Of course it is doable, but I think a navigation as unordered list is used on nearly every website so a module for it seems appropriate.

Hi Soma,

well... I am impressed! This is exact the way how I would do it ;-) Perfect! Im am eagerly looking forward to use it. I am MODX user since 6 years, but disappointed by the current development (extJS, slow manager, you all know it) and this chaotic business model. PW really seems to be as flexible and the roadmap is a dream (matrix thingie, draft mode, versions, form generator etc.). I think I will start an extra thread with some questions, nice to see MODXers here which then know what I am talking about ;-)

Greetings from Germany,

Marc

Share this post

Link to post

Share on other sites

Yup - a module is definitely easier when you get to recursive submenus. If you want something that will show a lot of pages with multiple levels of submenus it would be good to have the module cache the output (if t doesn't already).

Recently Browsing
0 members

Similar Content

I got tired of having to open the link dialog in CKEditor in order to check where a link is pointing to, so made this simple plugin.
Link Hover
A plugin for CKEditor. Shows the href attribute of a link in a tooltip when the link is hovered. This saves you from having to open the link dialog in order to check where a link points to.

Installation
This readme assumes installation in ProcessWire CMS.
The plugin folder must be named "linkhover" – if necessary, rename the folder to remove the "-master" suffix added by GitHub. Copy the "linkhover" folder to /site/modules/InputfieldCKEditor/plugins/
In the field settings for each CKEditor field that you want to activate the plugin for, check the "linkhover" checkbox at Input > Plugins > Extra Plugins

I've been reading through the tutorials and have created an admin module based on the ProcessHello example module.
I have a few questions regarding how to do a few things with the module that are not obvious or covered by the processhello tutorial.
Outline of expected module functionality:
The custom module admin setup page should contain a list of its editable pages.
CMS users will be able to add/edit/delete pages of this module.
The modules editable pages use the same defined fields.
The editable pages data will need to be available for use by another custom module.
This custom module (called "Stream Encoders") will handle creating/updating/deleting of "Stream Encoders".
The encoders contain various fields such as encoder name, operational status (is it on or off) and brightcove asset ID
A second module in "admin>setup" called "Video Streams" will handle creating/updating/deleting/scheduling of "Video Streams".
Each video stream belongs to a video encoder and uses some of the settings from the encoder selected, such as the encoder title and the brightcove asset ID which on the frontend are used to display the video stream.
My noob questions:
Since they are not "pages" in the navigation tree, how do I define these "encoders" to add them to the custom stream encoders module?
I don't believe my custom modules should be under "Setup", is it possible to have custom menus in the admin? It's fine if they can't but it would be more intuitive if they had their own menus in the admin instead of living under "Setup".
Without having a specific page on the frontend for video streams, how would I access the data for a specific video stream from the home page? for example if I wanted to display a specific or random video stream in a sidebar on the homepage.
Are there any tutorials on using scheduling with custom modules? The video streams can be scheduled or turned on/off as desired by the CMS users.
thank you in advance

The module has been lying around on GitHub for some time now, so I thought I'd give it its own forum topic so I can give it a module list entry.
SymmetricEncryptedText
Symmetric encryption for text based fields (supports multi language fields).
Module page.
Link to the GitHub repo.
Description
This module adds an encryption option to all text fields (and those derived from FieldtypeText).
Field contents are encrypted using a symmetric key when a page is saved and decrypted when loaded from the database.
The module by default uses sodium (if loaded) in PHP versions >= 7.2, otherwise it falls back to the bundled phpseclib.
Multi-Language fields are supported too.
WARNING!
Setting a field to encrypted and saving values in those fields is a one-way road!
Once encrypted, the contents cannot be unencrypted without writing a program to do so. Disabling the encryption option on a field after the fact gets you encrypted "garbage".
Usage
Download the zipped module through the green button at the top right of the GitHub repo or (once available there) from the official PW module repository
Extract in its own directory under site/modules.
In the backend, click "Modules" -> "Refresh", then install "Symmetric Encryption for Text Fields".
Go to module settings. An appropriately sized, random key will be generated if this is your first use.
Copy the supplied entry into site/config.php
Add fields or configure already present fields. On the "Details" tab you can enable encryption for the field in question
Edit a page with such a field, enter a value there, save and enjoy
Existing, unencrypted values are left untouched until a new value is saved. That way, you can do a smooth upgrade to encryption, but you have to save all pre-populated pages to have their values encrypted in the database. Thus it is recommended to avoid adding encryption to already populated fields.
Advanced Usage
You can hook after SymmetricEncryptedText::loadKey to retrieve your key from somewhere else, e.g. a different server.

After building the ProcessMentions module and another autocomplete module for images, I found that I am going to need even more of these, but things were going to get repetitive. So I refactored the whole thing into a basic autocompletion module and individual "actions".
The result is Autocomplete for CKEditor (GitHub).
To try out,
Install the module and actions

Enable actions in the settings of any CKEditor field

Edit a page with this field, type "@" and some characters for the and enjoy
There are still a few things I need to implement. ATM, it only supports single characters as triggers for the autocomplete. I'd like to change that to combinations so I don't run out of special characters at some point. I also have to add a few more configuration options (like search only at the beginning or also in the middle of the searched string). The documentation for custom styling also needs some work.
I have tried to keep things generic. Implementing your own actions should be quite straight forward. The README at GitHub illustrates the main steps and the supplied action classes have inline documentation. I would love to get some feedback or even see some third party InlineCompleteAction implementations.

I love the option to export fields via the CMS, and wondered about using that export data in a module. Basicly, I'd want to configure a field using the CMS and then paste it's export data in the module code as a string, or save it in a seperate file I can read from the module code. Once I have that string as a variable or file, I'd want to run the same code the import option does... but then from my module code's install method!
Is that possible? It would save a lot of time configuring fields through the API.