[SOLVED] one custom template for employee pages

Ask for help or provide support to other members.
Post Reply
ctuxboy
Posts: 15
Joined: Wed May 25, 2022 7:22 pm

[SOLVED] one custom template for employee pages

Post by ctuxboy »

Hello,

I will try building a website where every employee his own profile-page.
I know it is possible building custom templates for different pages:
- pagename: name-employee
- php-file: name-employee.php

What i will try to do, so i can use one custom template, for different employees.
For made this using subpages:

Code: Select all

website.com/employee/name1-surname1
website.com/employee/name2-surname2
...
I have some basic php knowledge.
My question: is there a way, with a if..then structure:

IF subpage-in-employee-dir THEN using custom template profile.php

PS: custom templates is a feature i missed a lot in WCMS, hope it's planned in the near future :?
Last edited by ctuxboy on Fri Oct 07, 2022 8:24 pm, edited 1 time in total.
ctuxboy
Posts: 15
Joined: Wed May 25, 2022 7:22 pm

Re: one custom template for employee pages

Post by ctuxboy »

Found a workaround/solution for my problem.

Here the code i adding in theme.php:

Code: Select all

<?php
  // get current $dir
  $dir = pathinfo($Wcms->getCurrentPageUrl(), PATHINFO_DIRNAME);
  $pattern = '/employees/';

  // if 'employees' in the url => profile-page-layout ELSE default layout
  if (preg_match($pattern, $dir)) {
    echo 'EMPLOYEE PAGE!'; // add here your specific template/layout
  } else {
    echo 'DEFAULT PAGE!'; // default template/layout
  }
?>
This is my use case:
The basedirs:
- https://website.com
- https://website.com/employee (when select a subpage from the employees-page)

All the employees are subpages from the employees-page

How the code works:
1. get current dir/url and add it to the variable $dir
2. test if the $pattern employees is exist in the variable $dir
3. if TRUE => subpage employee
4. if FALSE => default/root page

This snippet gives WCMS more flexibility, and very useful for a lot of usecases (articles, blogposts, profiles,..)
Hope it can help others :)
Last edited by ctuxboy on Sun Oct 09, 2022 7:04 pm, edited 1 time in total.
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: [SOLVED] one custom template for employee pages

Post by wiz »

Hello ctuxboy, have a warm welcome to the community.

You're awesome for providing a solution, however would also this help you? https://github.com/robiso/wondercms/wik ... e-template
ctuxboy
Posts: 15
Joined: Wed May 25, 2022 7:22 pm

Re: [SOLVED] one custom template for employee pages

Post by ctuxboy »

wiz wrote: Sat Oct 08, 2022 2:20 pm Hello ctuxboy, have a warm welcome to the community.

You're awesome for providing a solution, however would also this help you? https://github.com/robiso/wondercms/wik ... e-template
Hi @wiz,
Thanks for your help, loved if other people help thinking for alternative solutions, so we can learn from each other.

Reading the docs on github about using custom.layouts, but the problem with this, if you have <5 employees, you make for every employee a new php-file:
- employee-name-a => employee-name-a.php
- employee-name-b => employee-name-b.php
- ...

With my solution,
The if..then condition, looks in the URL, if 'employees' exists, then use the code/layout for showing the employee profile layout, and it is not nessesary using a php-file for every employee. If 'employees' NOT exist in the URL , then using the default layout.
Using this dir/url structure:
- /employees
- /employees/name-a
- /employees/name-b
- ...
- /employees/name-x

Also for a client, without webdev experience, the only thing what a client must do is adding a new subpage under the employees-page, so without adding a new php-file for every employee.

Hope you understand what i mean, my English is not so good 🙈
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: [SOLVED] one custom template for employee pages

Post by wiz »

ctuxboy, perfect explanation and I completely agree, your solution makes way more sense in this case.

We've expanded the WonderCMS docs/wiki to include your solution for these specific cases: https://github.com/robiso/wondercms/wik ... e-template

If you'd like, you can send your first, last name and website, so we can add you to our contributors page: https://www.wondercms.com/contributors

Thanks for being awesome and contributing to the project! Also your English is great, wasn't able to tell it wasn't your native language :)
ctuxboy
Posts: 15
Joined: Wed May 25, 2022 7:22 pm

Re: [SOLVED] one custom template for employee pages

Post by ctuxboy »

wiz,

Glad you understand my poor english and thanks for the compliments :)

Good news you extend the WCMS wiki/docs with this solution, it gives more flexibility on this tiny cms and maybe more developers will motivated WCMS in this case ;)

Yes, you may published my name, adding it in the 'Wall of fame' 8-) , thanks for this 'invitation' as new WCMS contributor, my name is Christophe Hollebeke.

At the moment i have no complete WonderCMS website project. I experiementing with a WCMS local installation, trying switch a client's website, build in WordPress converting to WonderCMS, so the client can edit by herself, when the project is finished.

My own (hobby) website is build in Automad (https://dogvalley.be/), but the last time, rebuilding this website in PicoCMS, so a work in progress ;)

After years design and developing with WordPress, i switched more and more to tiny flatfile cms-systems.
My favorites at this moment are:
- PicoCMS ( flexible, but has no backend, so not good for a client)
- WonderCMS ( less flexible, but very good with the UI for a client without webdev experience)

Regards,
Christophe
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: [SOLVED] one custom template for employee pages

Post by wiz »

I have to reiterate, your English is anything but poor.

You've been added to our contributors list, it's a list of everyone who has contributed to improving WonderCMS one way or another. :)
It doesn't really matter what your website it running on, however I'm happy to see you're playing around with WonderCMS and finding ways for it to be useful.

It's been around for about 15 years, meant to be really simple and customizable, especially if you know some PHP and/or is preparing something more than simple for your clients. It's kind of nearing the status of feature complete, while still retaining plugins/addons to make it customizable if needed.

What's still on the roadmap:
- PHP 8.1+ support/removing errors
- Summernote image compression
- Search function
- Supporting webp and avi for file uploads
- Bugfixes and other small improvements
- Possibly some snipcart or other shop plugin
- Possibly dependency handling

Thank you again, feel free to continue the discussion, always love hearing feedback.
ctuxboy
Posts: 15
Joined: Wed May 25, 2022 7:22 pm

Re: [SOLVED] one custom template for employee pages

Post by ctuxboy »

I have to reiterate, your English is anything but poor.
Thank you :)
You've been added to our contributors list, it's a list of everyone who has contributed to improving WonderCMS one way or another. :)
It doesn't really matter what your website it running on, however I'm happy to see you're playing around with WonderCMS and finding ways for it to be useful.
That's one of the reasons i love tiny cms-systems instead of big cms systems. It is a way easier building themes for such systems. With the big cms systems is a lot of 'bloat' and more difficult building theme's/plugins , and for a lot of websites, it is better using a simple fast system instead of a overbloated and slow (with MySQL) cms.

Really nice see WonderCMS gets regular updates and is actively maintained. Is one of my mininum requirements when choosing a CMS :)
Love to see whats planned in the roadmap especially the 'search'-function :P

If i may make one more suggestion for a core-update: more access to the database.js with functions. An example: it would awesome, in developer perspective, if it possible loop through the pages and subpages, it gives the system more flexibility.

PS: i see my code-snippet is published in the docs, thanks a lot for this ;) (https://github.com/robiso/wondercms/wik ... e-template).

Awesome work man :)
ctuxboy
Posts: 15
Joined: Wed May 25, 2022 7:22 pm

Re: [SOLVED] one custom template for employee pages

Post by ctuxboy »

Oops i found a (not important) typo in the comments in the code snippet:

// if 'medewerkers' in the url => profile-page-layout ELSE default layout

change to:

// if 'employees' in the url => profile-page-layout ELSE default layout

Forgot translate medewerkers to employees , yes i speak dutch :D

Sorry about that :oops:
Post Reply