power's avatar
Level 1

Theme system for cms

Hello everyone. im currently working on my own CMS and stuck on theme system part.i reviewed most of packages and open source content CMSs but they couldn't help much. is there any tutorial or pattern to help me build my theming system like wordpress that i can access to template tags in views ?

0 likes
13 replies
wottavm's avatar

but you can use blade correct ? I think I am missing the point here but please explain a bit more if you want.

power's avatar
Level 1

@concept_core i just want to know how can i implement theme system for my cms like wordpress or drupal ! just this.

ricardovigatti's avatar
Level 4

I think you will need create your own solution for that. Of course you might want to use some themes package, but they won't be that specific.

I've developed a similar solution using this package: https://github.com/caffeinated/themes. In addition to the package, it was necessary that I set the structure of folders and insert a middleware with a few logic to handle my themes.

You will need to use blade too. Correctly, as @concept_core said above.

2 likes
wottavm's avatar

If you try to do what wp does with shortcodes you should create a new blade directive that let's you do so. But you can also call functions in blade like you normally do with the blade functions.

1 like
power's avatar
Level 1

@concept_core and @ricardovigatti thank you guys.what's your idea about how to structure template files like index.php & page.php and so on also about how to implement template tags like wordpress ?

wottavm's avatar

@power Well how to structure would depend on the person who makes the templates I guess. I would create a base template file for the theme I am making which would never get called as a parent.

Instead I would create a page.blade.php for example which would extend from _template.blade.php.

As far as the template tags go, I would stick with laravel's default blade tags and create extra helper functions that a user can call. But also let them keep access to the main functions that laravel provides.

Question for you : How do you know which file needs to be called or how do you think you will achieve this ?

1 like
crnkovic's avatar

What I'd do (and I am) is I create Blade directives and view composers to share all the relevant data.

For example, I'll specify that in "blog/single.blade.php" file, there is a variable $author that gets relevant author information like real name, post count etc., and a $post variable that contains post information (title, content, published date, ...) and let the designer work. I'll also have some directives such as renderNavigation (dynamically created navigation based on what the CMS owner specified) and let the theme designer specify how to render it, e.g.

@renderNavigation('<li><a href="%s">%s</a></li>', '<ul>%s</ul>');

I also created some directives for checking if user is a guest or not, e.g. @online and have the $me variable.

That way I can make the CMS look any way I want because I only need the relevant information in Blade variables.

The theme is placed in its own directory and can be accessed via config file or via database (depends on your needs).

1 like
power's avatar
Level 1

@concept_core that's exactly my question how to build up these files in my system, that was invisible in my posts :). actually i confused how can i implement a system like this with strong conventions ?

Jaytee's avatar

@ricardovigatti wow never knew you were caffeinated. You're famous :)

Hey, can I take over your Gamification project?

wottavm's avatar

@power Well I do something almost the same but not quit. If you want I upload it to youtube so you can take a look.

It was a prototype that I made but I don't plan on finishing it. It does not use the themes package that was suggested but can be easily intergrated I guess.

Send me a message if you want the prototype and I will happily upload it to github

1 like
ricardovigatti's avatar

@Jaytee kkkk no no. I wish to have their skills, but i'm not the owner. I only used their package to develop my solution. I also use their Shinobi package for role and permissions.

@power, i've structured my pages at the "resources" folder. I have a folder for each theme there. (Here is where you can upload your CMS's themes). I also have a middleware who checks the route and sets the theme to be used. (Here, you will need implement the logic to define the theme to be used).

You have to play with the package and your application to discover which structure fits better for you.

1 like
power's avatar
Level 1

@jcrnkovic well, that's great you delve into your solution with example.what i found from your post is to declare bunch of variables and pass it to relevant views.what about if you want to get a list of authors in your index.blade.php ? Is $author accessible from this view ? I mean you share these variables for all views or its related to your conventions ?

Please or to participate in this conversation.