How to use another layout/theme file for different pages

Post Reply
iamnewhere
Posts: 1
Joined: Mon Sep 14, 2020 12:10 pm

How to use another layout/theme file for different pages

Post by iamnewhere »

Hi all, I'm giving wondercms a try after using getsimple for quite some time.

What I'm wondering is how I can create a theme that does the following:

/ = homepage -> users theme.php as its theme file (this works, following the easy 8-step guide online)
/mypage -> this should use a slightly different layout file than the homepage

I can't figure out how I can embed content in different templates. Another explanation would be a simple blog where the homepage looks different from the blog details page.

Thanks for pointing me in the right direction, I hope this is supported somehow.
User avatar
mjxl
Posts: 43
Joined: Thu Jan 30, 2020 4:57 am

Re: How to use another layout/theme file for different pages

Post by mjxl »

So instead of creating a completely new template (theme.php) file, you could look at just loading different CSS in other pages.

A really simple way to get there is with a some small cheats in theme.php!

Look for this:

Code: Select all

<link rel="stylesheet" rel="preload" as="style" href="<?= $Wcms->asset('css/style.css') ?>">
Change it tot this:

Code: Select all

<link rel="stylesheet" rel="preload" as="style" href="css/<?= $Wcms->page('title') ?>.css">
Now you will have to change the default css file (style.css) to whatever your homepage's title is.

In my case it would be "css/home.css" (index) for the homepage, and "css/stuff.css" (new file) for my stuff page.

Not sure if this will cover your needs?

Otherwise a plugin could work, or even a simple piece of javascript in your page that has something like:

Code: Select all

if (location.pathname !== '/') {
	"dosomething really awesome here"
}
Pathname is everything behind the domainname, so if pathname is NOT '/' (meaning, you are on the homepage!), do something cool with it.
Post Reply