Is conditional template overriding part of the Jekyll framework? - jekyll

I'm interested in using Jekyll to host a dozen business websites that share a lot of information and web interfaces in common. Hence, I'm curious if what I'm about to ask is easily supported by Jekyll.
If this were another website platform like WordPress, Magento, etc.. etc... I might set up default templates for my website like this:
tpl/default/header.html
tpl/default/footer.html
tpl/default/privacy-policy.html
tpl/default/pricing.html
tpl/default/contact/map.html
tpl/default/contact/form.html
Then for each business that signs up with me, I will set up a folder for them called tpl/<businessname>/. Then, the platform will create a website using all the html files in the tpl/<businessname>/ directory. Whenever a template does not exist in the tpl/<businessname> directory, then the platform will use the corresponding template in the tpl/default/ directory.
As an example, let's say Bicycle Shop wants a website from me. I go ahead and create this:
tpl/bicycyle-shop/contact/map.html
Then in my layout files, I might make calls like this:
<?php
define('ORG','bicycle-shop');
put_tmpl('contact/form.html'); // this will use tpl/default/contact/form.html
put_tmpl('contact/map.html'); // this will use tpl/bicycle-shop/contact/map.html
function put_tmpl($tplname) {
if(file_exists('tpl/'.ORG.'/'.$tplname))
include('tpl/'.ORG'.'/'.$tplname);
else
include('tpl/default/'.explode('/',$tplname)[count(explode('/',$tplname))-1]);
}
?>
I'm curious how a behaviour like this is achieved in Jekyll?
ADDITIONAL
One way that just occurred to me was to have a _config.yml that has variables like:
tmpl:
home: tpl/default/header.html
pricing: tpl/default/pricing.html
...etc...
Then each business has _config<businessname>.yml that overrides the appropriate tmpl variables. Would that be the Jekyll convention? Or is there something out of the box with Jekyll that does this better?

There are themes... you just install a theme as a gem in your config. When you need to override a theme file, you just put that file in your _layouts or _includes directory.
Super simple.

Related

When to create a module in Yii2 Advanced template?

I am little confused before starting a new project in Yii2 advanced template. So, i am asking this question.
I have done some projects in "Yii2 basic" app in which we use modules for different parts of our application like for adminpanel, api we create different folders in 'modules folder'.
I had also done a project in Yii2 advanced template it was multiapp project so we used advanced template. As we already had 'backend' and 'frontend' separated in Yii2 advanced template so we didn't created any module in 'modules' folder.
Now, i want to ask what is right approach. like in my new project we have users and products in backend so is it appropriate to create different modules for them in 'modules' folder or will it be ok if i create there controllers and models directly in backend folder.
what are the advantages of using modules folder in advanced template?
Thanks for answers in advance.
The advantage of module's use is primarly the possibilities of a resue of this components in several diffferente project. you can easly separate you common repetative functionalities in several modules and use the same code in different prject indipendently of the "template" or scaffolding you use for the single applicazione or group of applications.
Do the fact the modules are self-contained software units that consist of models, views, controllers, and other supporting components
modules are, not only usable as a sort of mini-applications, but also as a easy way for code organization and reuse.
Modules are used to reduce our work.
Example:
In most of projects have user login function like login , signup ,
forget passsword ,password reset.
If you write code for these functions as module . You can use any
project
So there is know need to write one code again and again.

PhpStorm - extend PHP Class template

I'm trying PhpStorm. I like the File Templates functionality and I'd like to use it in some more specific cases.
I'd like to extend to PHP Class template to create a new template that I'll be using for a specific type of classes. If I just duplicate the template, it doesn't really work as I'd expect. For example, while when I use PHP Class, the namespace is already compiled, this does not happen with my new template.
Is it possible to create another template so that it works as PHP Class?
Moreover... is there a way to order the templates in the editor, so I could have my new template near all the other PHP templates?
Is it possible to create another template so that it works as PHP Class?
Unfortunately not; at least not in current versions (2016.2).
When you are using New | PHP Class you see special dialog box that works with 3 templates (depends on what you will be creating: Class, Interface or Trait). This dialog uses file templates with predefined (default) names only and you can customize them as you wish .. but all other file templates for .php files will be just ordinary File Templates without those extras.
Based on your requirements you might be interested in https://youtrack.jetbrains.com/issue/WI-21711 ticket -- watch it (star/vote/comment) to get notified on any progress.
Please note that file templates could be project-specific (different template content for each project) -- this might be enough in some (rather simple) cases.
Moreover... is there a way to order the templates in the editor, so I could have my new template near all the other PHP templates?
Unfortunately not -- no sorting/subfolders is available (although you may have project-specific file templates).
Right now I may only suggest to use some common prefix in template name and build your sorting order around this idea.
Other than that -- https://youtrack.jetbrains.com/issue/IDEA-75239 + https://youtrack.jetbrains.com/issue/IDEABKL-3599 -- watch these tickets (star/vote/comment) to get notified on any progress.

Create versioned documentation archive

I am in the process of rebuilding a API documentation site for an open source project where we want to keep an archive of previous releases. I am wondering how I can configure Jekyll to generate the right hierarchy?
We have the following directory layout in our current /docs folder (which we would like to reuse in Jekyll somehow):
current/
v1/
v2/
v3/
Whenever we release a new version the current folder gets copied to a new folder (say v4). The contents of each folder is something like this:
introduction.md
testing.md
api-foo.md
api-bar.md
I'd like these to be available under the url domain.com/v3/testing/, domain.com/current/testing/, etc. I see that I could probably employ collections to do this, having one collection per version. To do this I see myself auto-updating the _config.yml as part of a build script (I made an example doing this here), but I am not sure how to progress from here, or if using collections for this is the wrong approach ...
This is too brief of an update to be of real quality, but thought I would mention that we solved this in the end in the Sinon project. Check out the repo at GitHub sinonjs/sinon and see the docs folder as well as the scripts called from package.json.
Feel free to improve on this answer by editing it and adding content and links.

yii2: where do my project's own html, css, js, and php-include files go?

Choices:
create an asset bundle (nicely explained by Ivo Renkema at How do I manage assets in Yii2?). this is what I need if I want to package my code for other use. alas, should I also do this for my own php include library functions? Or should I still stick them into the same php location as my other php files? In any case, if I want to go this route, presumably I would then customize the AppAsset class, included in the template, as explained in http://www.yiiframework.com/doc-2.0/guide-structure-assets.html .
stick my files directly into $basePath/web, where $basePath is typically something like /var/www/myapp/ (i.e., as $basePath/html/mine.html [and refer to it simply as href='/html/mine.html'], $basePath/css/mine.css , $basePath/js/mine.js, and $basePath/php/mine.php [and refer to it as $basePath= \Yii::getAlias('#webroot'); require_once('$basepath/php/mine.php') ])?
stick my local files where my php view code sits. the advantage is that the files are close to where I will use them. the disadvantage is that I may litter the view directories not only with php files, but also with my non-asset assets, even though they will be used only by these (my) php files.
it's a beginner's question for the google cache reference. it's about best practice when getting started. I can guess the answer, but we wouldn't want a novice to disseminate bad info.
If you need your CSS and JS files only in one view or one Controller you have 2 choices:
1- Create a asset bundle Here other guide if you need it.
2- Use registerJsFile() from View Class
You can acces from controller using:
Yii::$app->view->registerJsFile('js.path');
(Same with CSS files but using registerCssFile())
With the PHPfiles I always try to convert the code to yii's MVC. If you have a entire library try to add it as a component. Here a usefull guide

Cakephp 2.4.5 Custom HTML in baked views

I have been reviewing documentation in the cookbook to generate custom HTML in baked views and I'm having difficulty in getting my custom code to run during the bake process.
I followed the instructions as stated which are:
Modify default HTML produced by “baked” templates¶
If you wish to modify the default HTML output produced by the “bake” command, follow these simple steps as outline at http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html
For baking custom views
Go into: lib/Cake/Console/Templates/default/views
Notice the 4 files there
Copy them to your: app/Console/Templates/[themename]/views
Make changes to the HTML output to control the way “bake” builds your views
The [themename] path segment should be the name of the bake theme that you are creating. Bake theme names need to be unique, so don’t use ‘default’.
For my "theme" I chose the name dalma and placed my modified versions of the view generation code in
app/Console/Templates/dalma/views/
and then rebaked a specific table and none of my changes appeared.
I had assumed that I would be prompted for a theme when I ran the bake from the CLI which was not the case.
I then found instructions which talk about assigning a theme in the AppController which I did and this did not help.
Next I found another article http://www.dereuromark.de/2010/06/22/cake-bake-custom-templates/ that talked about placing the custom code in the app/vendors/shells/dalma/ directory and this did not work
I would appreciate any assistance.
You have to have a layout specified in your appController that matches the folder name in Console/Templates
appController.php
public function beforeFilter(){
$this->layout = 'bootstrap';
}
Console/Templates/bootstrap has my bake template.
With this setup the bake console prompts me for a template choice. (there may be other ways to specify this)
Here is my custom bake template which should help. (this is a forked work and not all my original code)
https://github.com/arco000/BootstrapCake