How is it possible to set up a shared view script path for partials to create global partials within the Zend Framework?
We know that you can call partials between modules
e.g - echo $this->partial('partial_title','module_name');
but we need to set up a partial folder in the root ( i.e below modules) so that it can be accessble by all views.
It has been suggested to set up a shared view script path, how is this done?
Zend_View has a method called addScriptPath, so in a Zend_Controller_Action subclass you could do something like:
$this->view->addScriptPath("/path/to/your/view/scripts/");
Now when you call render or partial or partialLoop, that path will be included in the paths.
I have got a solution. We can do this by specifying the location of the view:
Calling partial as above form Module/Controller page
Method 1:
$this->view->addScriptPath("/ModuleConatinerDirectory/ModuleName/view/scripts/");
Then load using:
$message = $this->view->partial('templates/default.phtml','contact',array('var'=> 'var');
For the second option, please read the following:
http://framework.zend.com/issues/browse/ZF-6201
Now my doubt is, whether it is possible on setting it directly on Bootstrap file for all my Modules ? If so, how can I set this for two modules Module1 and Module2
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper( 'viewRenderer' );
$viewRenderer->setViewBasePathSpec( '/some/absolute/path/to/templates/:module/' );
Related
I am working on a Laravel project and I am very new to it. For now, I want to use blade templates to render views but I want it to search for views in different directories like <custom_dir>\views instead of default resources/views.
The <custom_dir> will be dynamic (it can be a variable).
Any ideas? I was thinking of a custom service provider and then extend the default function which renders views in Laravel inside it. But not sure how to implement it.
Edit:
I have user this link to extend the default functionality of include function in blade template engine. But this overrides the include functionality. I want to change the path and then call the default blade functionality
You could probably append the path to the configuration:
1) Statically, by modifying file config/view.php
'paths' => [
realpath(base_path('resources/views')),
//more paths here
],
2) Dynamically at runtime:
$paths = config('view.paths');
$paths[] = $newPathToAdd;
config(["view.paths" => $paths ]);
I suggest you use this in moderation otherwise you will just end up with a mess of directories with no real specified purpose.
You can create custom directories in resources\views directory and use them with something like this:
return view($customDirectory.'.index');
Where index is a template inside custom directory.
Is it possible to display a view of a component without iframe and plugin?
(That is to say, if possible with a few lines of PHP and maybe SQL queries?)
EDIT:
To be more clear: I'd like to do it directly in the PHP-Template!
(Would be fine to do it in an article as well, as I have written a
PHP-function showArticle(mixed $ident))
(I'm using Joomla 3.5)
I'd like to do something like
<jdoc:include type="component" view="example" name="position-x" />
or
<?php
show_component('component-name', 'view-name');
?>
you can use this component http://extensions.joomla.org/extension/components-anywhere
Install the plugin and enable it.
Then you can call the component this way {component url/of/the/component}
{component index.php?component=com_example&form=1}
Try to use non-sef urls in the url but sef url will still work.
There is another way to achieve this by calling the model into your controller file this way
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_example/models', 'ExampleModel');
What this does is it searches the model class starting with ExampleModel in the folder specified. here you can eneter just a path string or array of the directories as the first parameter. Next you have to call the method inside the views file this way
$exmodel = JModelLegacy::getInstance('Something', 'ExampleModel', array('ignore_request' => true));
So here you create an instance of the class object which can be used to get the items from the model this way
$items = $exmodel->getitem();
$this->assignRef('items', $items);
next you can copy the default.php file in the tmpl folder of that component and place it anywhere you like inside your layout file. Basically instead of copying the entire component you are calling the model and getting the data which you can use in your layouts.
I have two versions of my project. For one i use a different CSS and index page and for another i use different. Rest of the things that is controller, models and components are same. The only difference is in view(one or two files) and CSS.
Is there any way to manage this? Like when the URL is URL1 then use CSS1/View1 folder and when url is URL# use CSS2/view2 folder. I have gone through the modules section of Yii but i don't think they are what i need here.
So now I started to use themes. My folder structure is like:
WebRoot
- assests
- css
- images
- protected
- themes
- theme1
-views
-site
-layout
-template
- theme1
-theme2
-views
-site
-layout
-template
In my controller I have done this:
public function init() {
if (SITE_TITLE == 'xxxxx')
Yii::app()->theme = 'theme1';
else
Yii::app()->theme = 'theme2';
parent::init();
}
Which sets theme correctly. but i keep getting file not found as renderer is looking in protected.
I think, you need use themes. Here is documentation: http://www.yiiframework.com/doc/guide/1.1/en/topics.theming
UPDATED after discussion
Trouble in ETwigViewRenderer and it working with themes
If you want to change entire layout, perhaps this is a good way to do:
Setting Layout in Yii
In case you want only to change css they why don't you rely on request uri or domain name?
Yii::app()->getBaseUrl(true)
In my Laravel 4 application's root directory, I have a folder themes. Inside the themes folder, I have default and azure.
How can I access view from this themes/default folder in a specific route.
Route::get('{slug}', function($slug) {
// make view from themes/default here
});
My directory structure:
-app
--themes
---default
---azure
I need to load views from localhost/laravel/app/themes/default folder. Please explain this.
This is entirely possible with Laravel 4. What you're after is actually the view environment.
You can register namespace hints or just extra locations that the finder will cascade too. Take a look here
You'd add a location like so:
View::addLocation('/path/to/your/views');
It might be easier if you namespace them though, just in case you have conflicting file names as your path is appended to the array so it will only cascade so far until it finds an appropriate match. Namespaced views are loaded with the double colon syntax.
View::addNamespace('theme', '/path/to/themes/views');
return View::make('theme::view.name');
You can also give addNamespace an array of view paths instead of a single path.
Here I am not accessing my project from public folder. Instead of this I am accessing from project root itself.
I have seen a forum discussion about Using alternative path for views here. But I am little confused about this.The discussed solution was,
You'd add a location like,
View::addLocation('/path/to/your/views');
Then add namespace for theme,
View::addNamespace('theme', '/path/to/themes/views');
Then render it,
return View::make('theme::view.name');
What will be the value for /path/to/ ?
Can I use the same project in different operating system without changing the path?
Yes, we can do this using the following,
Put the following in app/start/global.php
View::addLocation(app('path').'/themes/default');
View::addNamespace('theme', app('path').'/themes/default');
Then call view like the default way,
return View::make('page');
This will render page.php or page.blade.php file from project_directory/app/themes/defualt folder.
I've developed a theme package for laravel 5 with features like:
Views & Asset seperation in theme folders
Theme inheritence: Extend any theme and create Theme hierarcies
Try it here: igaster/laravel-theme
\View::addLocation($directory); works fine but the new right way to do it is using loadViewsFrom($path, $namespace) (available on any service provider).
I have two modules, default and mojo.
After the initial bootstraping code which is the same for both of the modules, I want, for example, to use different layouts for each module (Or use different credentials check etc).
Where do I put this: IF(module=='mojo') do this ELSE do that
If you are using Zend_Application (in ZF1.8) then you should be able to use the module specific configuration options to provide this functionality with a as explained in the relevant section in the documentation.
This would require you to set the layout in the config so it looked something like
mojo.resources.layout.layout = "mojo"
anothermodule.resources.layout.layout = "anotherlayout"
The layout would then be set automatically by the bootstrap.
The other alternative is to use a front controller plug-in that implements the preDispatch() method to set the layout based on the module name.
hmm i havent tried this
http://www.nabble.com/Quick-Guide-How-to-use-different-Layouts-for-each-module-to23443422.html#a24002073
the way i did that now was thru a front controller plugin
something like
switch ($request->getModuleName()) {
case "":
// set layout ...
}
I've looked into the subject a couple of days ago, trying to get it to work on bootstrap config alone. The big problem is that all the bootstrap files are loaded, so it gives some weird results in which layout is used.
My conclusion was that you can have the config in place, but you need to work with FrontController plugins or ActionController helpers. If you want to use config set in the application.ini and you want to load the config trough the bootstrap, helpers is the only way to go. From the helper, you can then load the ActionController and on that execute the getInvokeArgs to load the bootstrap. A lot of hastle... :)
Anyway, I've done a small implementation as an example in a blog post: http://blog.keppens.biz/2009/06/create-modular-application-with-zend.html
Goodluck,
Jeroen