Separating templates from logic in WordPress - wordpress

I'm wondering the best way to separate my plugin's templates from the actual logic. Currently I use a series of actions & filters to enable theme authors to alter controls ect from my plugin but it's not very intuitive.
I've heard of template engines like twig but not sure on how big the uptake is on these & whether it might confuse more than it helps.
Does anyone have any experience with this in WordPress?
Thanks

By my experience of plugin development, I have come up with a simple MVC like way separate plugin files. Basically what you can do is use the same folder structure that WordPress core uses. For example, if your plugin name is 'Related Posts' (rp), then the folder structure can be as follows:
wp-content/plugins/root_plugin_folder/rp-admin : This should contain all files which are needed for admin interface of your plugin. Typically the view files for your options page etc.
wp-content/plugins/root_plugin_folder/rp-content : This should contain all plugin's template files. This folder can also store stylesheets, js - basically all that is used within the theme
wp-content/plugins/root_plugin_folder/rp-includes : This is the folder for all model files, includes your plugins core libraries, any other libraries used. Basically pure php code of model or view type.
wp-content/plugins/root_plugin_folder/index.php : This file will be the bootstrap which will have plugin name, description markdown and plugin initiation filters and actions etc.
Hope this helps.

Have you ever used the model-view-controller (MVC) method? Its a method of programming to separate logic from presentation.

Related

New to Drupal 7: Trying to figure out CSS

I inherited an already built Drupal 7 site. I have been able to figure out many things. But I am unclear on the CSS. A found a folder full of long-named CSS files but the code is all minified and hard to read. The previous developer had to be using some tools or services to alter and change the code in a more readable way. Does any know what the deal is ?
Also, I cant seem to find any way inside Drupal to enter CSS. I do not even see any classes or ID assigned to the blocks, views, nodes, or fields. So I have no clue how they were able to customize this site at all even though they obviously did. It uses Bootstrap 3 as a theme. Can anyone help explain how this works?
I will try to figure out the essence of the informations you given.
First: You have a Drupal 7 installation with compressed css files based on Bootstrap. That sounds the theme use less or sass precompiler for the theme css and you have the production (builded) instance of the project. Without the uncompressed less/sass/scss files it will be hard to edit the css. if you have no way to get the source files, the best way you can try is to add a extra css file and write you own css in it.
Second: Drupal strictly separates the code from the administration interface. Your PHP, HTML, CSS and other codes (except the WYSIWYG output) should not be entered via the administration interface. That's the best practice way. But anyway, there is a couple of modules that allows to write code inside the Drupal backend like this https://www.drupal.org/project/extra_css_js
Third: As information for you, Drupal 7s End of life is on November 28, 2022 so the best and recommanded way for you is: Freeze the Drupal 7s Instance as is (only Sercurity Updates and Hotfixes) and relaunch the Project with Drupal 9.
Drupal theme css files are mostly located in theme folder like "theme folder/css/style.css". As above mentioned, it might be used css minify tool or module for theme performance aspects. If it is created by drupal tools/module then once cache clear it will delete automatically and regenerate with new one with updated new css code on after page visit. You can also add custom css file by hook alter.

Adding non-blog files in a blogdown Web site

I am trying to construct a Web site with blogdown, Hugo, and the xmin theme. I would like to store some Markdown files in a subdirectory, say content/misc/, such that they are not going to be treated as blog entries (e.g., they will be pointed to specifically on some _index.md pages).
How can I do this for single files or for all files in a subdirectory of content/? I know I can kind of hide them directly in the content/ directory, however this makes structuring the project clumsy and difficult.
I suspect this will be possible with specific templates, but is there an easier, much simpler way to handle this requirement? Or are there more appropriate themes to make it possible?
If there are some pages that you want to show with a common format, but you do not want them to be listed in your blog articles list
Simple solution: use the default template
To use the default template, you just need to add this "misc" folder in "content" with all your Rmd inside. Then, there will be a page listing all the articles of this type at "myblog.com/misc/".
Advanced solution: use a specific template
If you want to have a specific template for these pages.
If it does not exists, create a "layouts" folder at the root of your project.
Inside "layouts", create a "misc" folder
Inside "misc", create a "list.html" file if you want that your page "myblog.com/misc/" shows a list of your pages with this category
You also need to create a "single.html" if you want a specific way of showing these single articles.
To have ideas what to put inside these two files, you can directly start with the template of your own theme (https://github.com/yihui/hugo-xmin/tree/master/layouts/_default). As I said, you can also look at the "itemized" type of "hugo-future-imperfect" (https://github.com/statnmap/hugo-future-imperfect/tree/master/layouts/itemized), or what I propose for sticky pages on "hugo-statnmap-theme" (https://github.com/statnmap/hugo-statnmap-theme/tree/master/layouts/sticky_pages)

What is the best way to implement a theme / template in meteor or angular-meteor

I've been having trouble implementing templates bought in themeforest in a meteor app.
I'm wondering, what would the best way to implement a template into a meteor app.
Two ways that I think of right now are:
(Tedious way)
Place javascript in Compatibility folder and try to name them in specific alphabetic order in order to get them to work properly.
Place css in client/lib folder and try to name them in specific alphabetic order in order to get them to work properly.
Place fonts and images in the public folder.
The second way (I haven't tested it yet) is to place the template files in the public folder and just link them manually (the old/non-meteor way) in the index.html file.
Now I'm not sure if these are the correct ways to do this and I would like some information regarding this issue.
Thanks!
I've done this myself with a themeforest theme.
Put the theme's css file under /client - it doesn't need to be in /public
Use the class names your theme uses in your templates. Typically a theme will have 3x what you really need so this ends up being much less work than it might seem. If your theme is built on bootstrap then it's even easier.
My theme used fontello a lot for icons, I had to recreate the folder hierarchy under client/fonts and then make sure the cross-references were correct.
Typically themeforest themes don't use js that much, I completely ignored all the js that came with my theme and created what I really needed in Meteor.

Migrating an XDV theme product to Diazo

I am attempting to migrate from XDV to Diazo.
Currently I have a theme product that contains:
a custom navigation.py and layout.py
folders for:
overrides (for core overrides)
profiles (eg cssregistry.xml)
static (the theme resources, rules.xml, js, css and other cruft we may want to be able to call generically from the static directory with /++resource++theme/ syntax)
unit tests in tests.py.
My question is: does all of this come across to the Diazo theme or will i still need the current theme product installed for some parts of it?
I think so, yes.
overrides/ and profiles/ are the same.
The registration in configure.zcml for the rules URL should change to a one, and this will change the URL (++theme++ instead of ++resource++) but it's very similar.
There are some syntax changes, but they are minor and detailed here: http://pypi.python.org/pypi/plone.app.theming
Martin

In Drupal, how do I override a template in a core module without modifying the actual core?

I want to edit the search results of a search using the search module. The template in question is search-result.tpl.php. I see that it's in html/modules/search, but I'd like to keep the modification out of the core and keep it in my sites folder. Is there a way to change the place that drupal looks for that specific template? If not, how can I accomplish my goal?
Copy the search-result.tpl.php into your theme's directory, modify it as needed, and clear the theme cache.
You may also want to check out the About overriding themable output handbook page for additional details.

Resources