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
Related
I have just started using PhpStorm. In my project I am receiving a lot of undefined variable errors because I am creating a plugin for vBulletin.
I was wondering is there a way to include the main software I am working with in my plugin development, to avoid getting undefined vars, and functions? Kind of how the WordPress plugin development works.
For example I have my projects folder: c://wamp/www/projects/projectname/ and I have vBulletin in c://wamp/www/vb3/
I want to be able to tell PhpStorm "hey the core scripts to this project are here".
As LazyOne said I was able to achieve this using include paths.
Include paths are used for holding third-party code that is used for completion and reference resolution in some functions/methods that use file paths as arguments, for example, require() or include().
Note that the files added via include paths are not meant to be edited within the scope of your project. If you have the existing code that you need to access and modify from within several projects, consider adding it via an additional content root.
Do one of the following:
To configure the include paths for the current project, in the
Settings/Preferences dialog Ctrl+Alt+S, click PHP under Languages &
Frameworks.
To configure the include paths that will be applied to all newly
created projects, use the default new project settings (File | New
Projects Settings | Settings for New Projects ).
On the PHP page that opens, configure the list of include paths on the Include path tab:
Use Add and Remove to add and remove paths.
Use Move up and Move down to reorder the items in the list.
Click the Sort Alphabetically button to sort the paths alphabetically in the ascending order.
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.
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.
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
Sorry for the noob question but I'm trying to start up a new application with Sails and include my assets. I'm using Bower to manage my packages for things like Bootstrap and JQuery. I had a read of this question and added a .bowerrc file which is now installing my Bower components to /assets.
I'm now confused as to how I should proceed to add these files into my project. It seems as though I can't just do a <script> tag in the header as I'm used to because it's giving me a file not found. Reading through the sails documentation it seems like Grunt should be creating a .tmp/public/assets folder in my project, but whenever I run sails lift and go to .tmp/ there is nothing in there.
I also read in the documentation that I should be using some kind of asset injection, I tried adding this to my HTML and it seems like it doesn't do anything.
My other question is around how I go about referencing images in my HTML. Obviously I can't just do something like src='assets/images/image.png, how should I go about this? Is there something really obvious that I'm missing?
Sails use grunt tasks to do lot of things during lift and build. You can get much better look how everything work if you take some time and check what is inside Gruntfile.js from root of your sails project.
About your specific question here is some information:
- from sails docs: "In order to take advantage of asset injection, minification, and concatenation you must put your assets in folder under assets/linker". This exactly mean that everything what you will put inside assets/linker directory will be affected by grunt tasks during lift. It mean that all files/directories from linker will be copy to .tmp/public and also some of that files will be processed before saved to .tmp/public.
- About adding tags. If you take a look at Gruntfile.js you will find this variables: var cssFilesToInject = [...] and var jsFilesToInject = [...] which contain files that will be automatic added to layout header during sails lift.
- About your 'other question', yes you can do something like 'src='linker/images/image.png' if you move that files to linker directory (assets/linker).
I hope this help :).