HTML5Boilerplate with Yii Framework - php

Has anyone managed to integrate HTML5 Boilerplate in the YII PHP Framework (specifically the folder structure and build process)?

Boilerplate recommends using the #import when adding styles to the head.
<style>#import(/example.css);</style>
Yii uses the ClientScript model to add
<link type="text/css" src="/example.css" />
Use the Yii::app()->clientScript Model to register the file. Yii allows you to register script files as needed, per controller or per view. Therefor your http requests can be minimal. I would suggest registering the required scripts/css in the main layout and add other scripts as they are needed with the
Yii::app()->clientScript->registerScriptFile();
Yii is based on the MVC model. The V is for view. The view foldes contain the html elements your model and controller will adjust based on data types. Inside the view folder Yii uses the layout folder to define layouts.
$this->layout = 'main';
That line will look for:
Protected -> views -> layout -> main.php
The layout folder should contain main, _htmlHead, _header and _footer. The renderPartial will be used for render the different layout parts. It's like a php include for HTML. The second param of $this->render or $this->renderPartial is used to pass data to the view. For example nav data:
$this->renderPartial('_footer', array('nav'=>array('/link/'=>'Link Name')));
In the _htmlHead register the needed elements using the Yii::app()->clientScript. If you want to use a different version of jQuery then use the ScriptMap model, don't register jQuery twice. Yii's coreScript, validation and paging are based on jQuery.
$cs = Yii::app()->clientScript;
$cs->registerCssFile('/css/base.css');
$cs->registerScriptFile('/js/base.js', CClientScript::POS_END);
/* Load Script at END of DOM tree: CClientScript::POS_END */
http://www.yiiframework.com/doc/api/1.1/CClientScript
In the past I've used the config.php file in Yii to set an assetsLocaion parameter. If I move my assets it won't break the site.
Yii::app()->clientScript->registerScriptFile(Yii::app()->param->assetsLocation.'/js/example.js');
The basic layout of the boilerplate will be defined in the layout/main.php. Check out the theme documentation: http://www.yiiframework.com/doc/guide/1.1/en/topics.theming
Layout File Might look like this:
<!doctype html>
<?php $this->renderPartial('//layouts/_Htmlhead); ?>
<body>
<div id="container">
<?php $this->renderPartial('//layouts/_header); ?>
<div id="main" role="main">
<?php echo $content; ?>
</div>
<?php $this->renderPartial('//layouts/_footer); ?>
</div>
<?php $this->renderPartial('//layouts/_footerScripts); ?>
</body>
</html>

Check my Yii BoilerPlate and Bootstrap Integration
https://github.com/drumaddict/YiiApp

A simple Yii HTML5 Boilerplate theme is available at https://github.com/neam/yii-html5-boilerplate

There is a very detailed Wiki article by Antonio Ramirez titled:
YiiBoilerplate - Setup a professional project structure in seconds
http://www.yiiframework.com/wiki/374/yiiboilerplate-setup-a-professional-project-structure-in-seconds/
Sources for this setup:
https://github.com/clevertech/YiiBoilerplate

What about
https://github.com/clevertech/YiiBoilerplate
I think they Uses HTML5Bilerplate

Related

How to call ...blade.php in different folder inside views folder in laravel

Excuse me, i would like to ask about how to call another page blade in different subfolder inside views.
Example :
views
--home(subfolder)
--beranda(subfolder)
--refresh.blade.php
--layouts(subfolder)
--master.blade.php
in master.blade.php implements template page, when i click one link in this folder may have to go in refresh.blade.php.
Likely another web layout, they have a lot of link in header like 'Home', 'Paper', etc.
I'm still learned more about laravel as beginner practice.
May you can help me, i'll appreciate that.
Regard, Aga.
I think you can refer to some directives such as #include and #extends in the laravel blade.
For example, in the admin.common.header view (located at admin/common/header.blade.php), we have some basic page code (common to various pages such as navigation bar or layout). We use #yield such as #yield ("extra_js") or #yield ("extra_css") where we want to add code later.
header.blade.php
<html>
<head>
something maybe ...
#yield("extra_css")
</head>
<body>
something maybe ...
#yield("extra_js")
</body>
</html>
And in another view such as admin.feedback.feedback, you can use #extends('admin.common.header') at the top of the code to inheritance the template and you will get the layout of this template.
For different content in the feedback template, you can use #section to give you code to fill in the inheritance template such as #section('extra_js').
feedback.blade.php
#extends('admin.common.header')
#section('extra_js')
<script> something... </script>
#endsection
If you want to include one blade, just use #include.
<div>
#include('shared.errors')
<form>
<!-- Form Contents -->
</form>
</div>
In laravel blade there are many instructions to complete the rendering of the template, if you want to know clearly, please refer to the corresponding version of the official document.

Joomla Component: include/require php in View

this is my first time making a component for Joomla 3.
I'm trying to convert a php website to a component.
Almost every view of my php website is built this way:
Header
Sidebar
Navigation bar
Actual content
Footer
Scripts
So basically it looks like this:
A view from php website
<?php require_once('includes/header.php'); ?>
<body>
<div">
<?php require_once('includes/sidebar.php') ?>
<div>
<?php require_once('includes/navbar.php') ?>
</div>
<div>
<!-- Content or something -->
</div>
<?php require_once('includes/footer.php') ?>
</div>
<?php require_once('includes/scripts.php') ?>
<script>
</script>
</body>
</html>
But in Joomla this is not possible. If I try to include or require a php file like above it just doesn't work.
View in component looks like this:
com_component
../views
../tmpl
default.php
view.html.php
../includes
header.php
footer.php
sidebar.php
scripts.php
navbar.php
Default.php is supposed to show a dashboard on the frontend.
This is what I'm trying to do in default.php:
Default.php
<?php include_once('../../includes/header.php') ?>
<body>
<?php include_once('../../includes/sidebar.php') ?>
<?php include_once('../../includes/navbar.php') ?>
<!-- Some content-->
<?php include_once('../../includes/footer.php') ?>
<!-- etc -->
What I've done
I've found some JDocument and JHTML functions which can add stylesheets and javascript to the template. But that is not what I'm looking for.
I used Joomla's addCustomTag function but it only shows a commented php line in the template.
Tried to make a String of it and passed it through a variable.
Questions
Is it possible to include php files in a template (default.php)?
If not, is there any other way to do it?
If yes, is that good practice in Joomla?
Thanks
To include files in the same directory as the given file, you can use:
include __DIR__ . '/../includes/header.php'
If you don't use DIR the current path is related to the main page (index.php in the site root) and not to the layout (default.php).
A more Joomla compatible solution is to put all your "sub-layouts" in the same folder with a conventional naming like this:
com_component/
views/
myview/
view.html.php
tmpl/
default.php
default_header.php
default_footer.php
....
Then you can use in your main layout the following code:
echo $this->loadTemplate('header');
...
echo $this->loadTemplate('footer');
You don't need a component to do any of this. I mean you can
do this but it should only be as an intermediary step since Joomla is designed to make all this easier by having APIs to include modules which is basically what all your pieces are.
You'll notice that in the joomla template file there are places where module positions are loaded. These are things like menus, footers, sidebars etc.
Depending on what they are you should really make each of these subsections a module. In some cases you can probably use existing modules already in Joomla or make a "custom html" module if you are just loading some html. In other cases makin a joomla module is really easy, just a few files, and you can put your php code there, really to start you can put the whole thing in the tmpl/default.php for the module or you can split it between the helper and the layout.
You'll be much happier in the long run if you take advantage of using a CMS rather than fighting it.
Components are only for the "body" area, what you need to do is make a template and then the modules.

Codeigniter - Templating with separate templates

I wish to have a codeigniter application with 3 templates.
a template for displaying a login view, or an error view.
a template with header body navigation
a template with header body sidebar footer
now I can build the codeigniter application, but I can't find a simple template system to accomplish this task. There are many recommendations for libraries available, but they lack implementation details.
Suggestions and guidance would be appreciated.
You can user CodeIgniter Template.
http://williamsconcepts.com/ci/codeigniter/libraries/template/index.html
Download here the library and also you have a full documentation.
With this library, you can use more than one template, and you can manage it easy and separate in groups.
It's quite simple once you get your head around it.
You need to create a view file for each of the things you've listed above, so you'll want something like this (folder/file wise):
views/page-login.php
views/page-error.php
views/header.php
views/footer.php
Then from your controller you will load one of the page views.
Within the page view you can then load the elements you require, so header and footer with the page specific code between them.
So for example your login page could be:
<?php $this->load->view('header'); ?>
<h1>Login</h1>
<p>Please login to my website.</p>
<?php $this->load->view('footer'); ?>
This is fairly simple.
A quick example:
In your controller you can put
//a test variable
$data["foo"] = 'bar';
$data["page"] = 'a_page'; // this will make sure it loads the views/pages/a_page.php in your template
$this->load->view('templates/login',$data);
And in your views/template/login.php you can put:
<!-- your login template html -->
<html>
...
<!-- include the view you want inside your login template -->
<?php $this->load->view('pages/'.$page);?><!-- As you can see it loads /views/pages/a_page.php -->
<?php echo $foo;?> //This will echo Bar
</html>
or:
<?php $this->load->view('template/login_header');?>
<?php $this->load->view('pages/'.$page);?>
<?php $this->load->view('template/login_footer');?>
views/pages/a_page.php will also know $foo.
This loads another view (views/pages/a_page.php) in your template.
This way you can create all the templates you want, and include your view in those templates.
TIP: Handling headers & footers this way get's unmanageable pretty quickly. And it's still better to use template libraries. Try Phil sturgeon's library

Add comments to HEAD Zend Framework

Is there a view helper to add comments (not conditional comments) to the HEAD section of the page. I am using a layout approach.
On a couple of the view helpers supplied with Zend Framework you can use captureStart() and captureEnd() to grab comments. Not what it is designed for, but it works.
eg (in a view script):
<?php $this->headScript()->captureStart(); ?>
<!--some comment-->
<?php $this->headScript()->captureEnd(); ?>
Then in your layout echo $this->headScript() in the head.
This is just proof of concept. Most of the head view helpers will throw an error if you try this. It only works with headScript and headStyle. Of the two I would use headStyle as good practice these days is to have the styles in the head and scripts in the footer. Ideally you can write your own view helper to do this specifically.

Zend Framework - layout best practices for 'includes'

I'm pretty new to Zend.. I'm just wondering how to model my site's layout/structure. My site will have an user profile section, admin section, and the generic the default view of the site.
For the admin and profile, I'll have custom elements in the headers and footers, otherwise I want to default to a generic header/footer.
I want the ability to have an entirely custom skin separate from the default view, how should I structure things?
So far I have have created a directory in application/ named layouts. I have modified the application.ini file so it accounts for that:
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
So my default layout view now exists in application/layouts/scripts/layout.phtml, I have the header and footer embedded in this layout.phtml file but I would like to strip them out and have them in separate files.
Could anyone assist me in coming up with the structure for this? So to re-iterate I want a custom default layout, custom admin layout, custom user profile layout, and for all 3 layouts I want customizable heading/footer "includes" but I'm not sure how this is done properly in Zend as I'm accustomed to include files.
Directory structure:
/application
/layouts
/scripts
/layout.phtml
/profile.phtml
/admin.phtml
/_header.phtml
/_footer.phtml
layout.phtml:
<?php echo $this->doctype('HTML4_STRICT') ?>
<html>
<head>
<title>Bah</title>
</head>
<body>
<?php echo $this->render('_header.phtml') ?>
<?php echo $this->layout()->content ?>
<?php echo $this->render('_footer.phtml') ?>
</body>
</html>
profile.phtml:
<?php echo $this->doctype('HTML4_STRICT') ?>
<html>
<head>
<title>Profile</title>
</head>
<body>
<!-- profile header -->
<?php echo $this->layout()->content ?>
<!-- profile footer-->
</body>
</html>
FooController.php:
profileAction()
{
// do stuff
$this->_helper->layout->setLayout('profile');
}
This method allows you to change the entire page structure of different layouts (The admin suddenly needs a sidebar!). You trade off some code duplication for enhanced flexibility and maintainability.
If this is not important to you, a view helper would work also (query the Front Controller to find out if the request came from either the admin or profile actions, switch). For my tastes though, that type of logic is too involved to belong in the view.
If the view helpers are complex use concrete view helper. If they are simple like <h1>my title</h1> use partial view helper to render a template.
To have a different layout/config for various sections of a site, I use Modules with the following module setup.
Module Config
[Edit]
Directory Structure :
/application
/forms
/models
/modules
/admin
/config
/contollers
/layout
/views
/default
/config
/contollers
/layout
/views
An implementation that I use is as follows:
In each of the layout phtml files (default, admin, etc)
I use:
<?= $this->action('header', 'page', 'default') ?>
<?= $this->layout()->content ?>
<?= $this->action('footer', 'page', 'default') ?>
so in my page controller I may have an action called "headerAction" or "adminHeaderAction" which does nothing (or actually could perform specific tasks) but returns a header.phtml (where I can customize my header information for that layout). I can then customize my header and footer separate from the content.
In my controller I just need to set the appropriate layout:
$this->_helper->layout->setLayout('adminLayout');

Categories