Template declaration to dynamically find views in RoR - iphone

I'm trying to separate the views for the different platforms into different subfolders.
I have done this for the layout, at the moment I have the following:
class MoviesController < ApplicationController
layout :site_layout
def site_layout
if(iphone_request?)
"iPhone/movies"
else
"movies"
end
This means that in my action methods I don't need to include :layout, however I do still need to manually include the path to the template.
format.iphone {render :template => 'movies/iPhone/index'}
Is there a way to have the same kind of layout declaration but for templates?
Thanks
Ben

You may want to extend the view_paths so that you can have a special iphone subfolder under views and override templates as necessary. See this tutorial on how to do that.
However, is there a reason you don't want to use the iphone format in the view name (show.iphone.erb) instead of making a subfolder? See martinkl's answer in your other question for details.

I might be off, but maybe it'll help - try checking prepend_view_path.

Related

Display System Categories in TYPO3-FE

I am trying to build my first own extension with the Extension Builder. Up to now everything worked really well, but now I've got a problem and am not able to find a solution:
My extension looks like this: You can add new Entries in the backend under List (the entry on the right panel). These entries are then shown in the frontend.
While adding new entries there is the possibility in the horizontal navigation bar to link this entry to specific categories. I've already done this with every entry.
But how can I display this category in the fronted. It should be just one <div> like Linked Categories: CATEGORY.
It seems like there is no ViewHelper which can display all linked categories.
I've already googled a lot, but this just confused me more: It seems like its not possible with a simple ViewHelper. There was a solution, where one had to edit the controller. But I did not like this because then I can not continue working with the Extension Builder or it becomes overwritten.
I also looked in the code of tx_news. It seems like all categories are in a variable there, which can be looped. But in my extension <f:debug>{categories} was always NULL.
Is there no ViewHelper which can display the categories, or anything else? Maybe a good tutorial (I am good in PHP, but new to TYPO3).
Thank you very much in advance,
Felix
P.S: I am using TYPO3 CMS 7.6.9
the Extension Builder is just a 'kickstarter' that helps you define your models and actions, relations etc ... It will not do more then that. So once you created your extension draft, it's best to forget about the extension builder and try to understand the structure of an extbase extension (the MVC, TCA, localconfig, typoscript,...). If you need to add a new property, do it manually. You will learn a lot more about your extension and how it works.
Having this said, you will have to adjust your extansion yourself to add categories. There are a few ways to do it: you can add your own category system by adding your own category Model, or use the TYPO3 category API
https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Categories/Index.html
There is also no plug&play category viewhelper. If you like to be able to list your entries by category, you will need to adjust your controller.
You can add some functionality to an existing on, for ex. your listAction so that it reads arguments send to this action (a list of categories you like to filter on) or create a new one called for example categoryAction.
extbase reference :
https://docs.typo3.org/typo3cms/ExtbaseFluidBook/b-ExtbaseReference/Index.html
stackoverflow question about categories in a controller:
Controllers and Template (how to filter results correctly or give arguments via backend?)
bottom line:
- skip extension builder
- learn how to adjust the MVC yourself
you can always join the TYPO3 slack channel :
https://typo3.slack.com/
it's free and people are very helpfull
good lcuk

Zend Layout Placeholder?

I am trying to create a sidebar in my layout that has the behavior of a placeholder. I want to be able to define the contents of this placeholder once per controller. So every controller can add custom content to the sidebar but without the need to define it in any view.
I am kind of confused on how to go about that with Zend_Layout. Any help?
I have tried something similar. Here is what you can do.
Place this type of code in the layout.phtml script file. Somewhere near the top. You don't have to but this way you 'know' what placeholders you're using. Doing this in the layout is also a good idea because you can wrap html divs are whatever here and not worry about it in the views. The views can just worry about the content. After this, you can add content to the placeholders from the controllers and the views.
$this->placeholder('blah');
$this->placeholder('sidebar');
$this->placeholder('blunk');
If you don't want to create them in your layout, then you can do it in the controller like so,
$this->view->placeholder( 'sidebar');
.
Now, you can either put content into it in the controller, or in the view script. Its a better idea to add the content in the view though.
In the layout you can then just echo the placeholders like so
echo $this->placeholder->( 'sidebar' );
All the views are executed BEFORE the layout is executed so any placeholders created by the views will be available to the layout to print out.
Also, controllers don't HAVE placeholders. Only views, and by extension layout, have placeholders like this so you have to declare them somewhere. Even if you declare them in the controller they still 'belong' to the view object.
I don't know if this helps at all but good luck. Tell me what you think.
How about adding a postDispatch() call to each controller?
public function postDispatch()
{
// code to populate/activate your placeholder
$this->view->placeholder('xxx');
}
This function will be called after your action completes. For more info, see Pre- and Post-Dispatch Hooks.
i have just implemented a solution to this that should work for most uses.
I store all of my placeholder.phtml files in the following dir:
/views/scripts/_placeholder
Within the placeholder i create directories for each Controller / Action that has a placeholder (as well as ROOT stuff). I then create a file for each placeholder.
e.g. Placeholder = sidebar. Controller = user / action = view
for the above we would store a file here:
views/scripts/_placeholder/user/view/sidebar.phtml
note: within the sidebar.phtml you will need to add : $this->placeholder("sidebar")->captureStart() and captureEnd();
if the plugin sees this file it will render it. If it doesnt find one then it wont.
Additionally the plugin will also look for the following and pull that in first:
views/scripts/_placeholder/sidebar.phtml
I can post the plugin if you want.
The only issue i have is i would like to now know if a placeholder has any data in it. That way i can create some layouts that are clever and will render what needs. DOes anyone know how to do this?

Zend Framework Navigation - dynamically adding parameters

I am experimenting with Zend_Navigation to build breadcrumb for a web site. I created an XML file which lists the hierarchy of pages. Things are working fine for the most part except for pages that have dynamic parameters.
For example, there is a group page which has the URL " www.../groups/gid/1001". The id 1001 is dynamic so it changes for different groups. Because of that I cannot put it in the XML file. In that case, ZF generates a link without including any parameters, which of course won't work.
One solution I found is dynamically injecting the parameters to the Zend_Navigation object. This is working fine except that I need to do it for each action or controller.
Is there a better way to handle it? Does ZF have any classes to do this work?
I will appreciate any feedback.
Thanks!
http://zend-framework-community.634137.n4.nabble.com/Creating-a-dynamic-database-based-Zend-Navigation-item-td660805.html
And/or start reading here: http://framework.zend.com/manual/en/zend.navigation.introduction.html
At which point do you know the group ID to use in the navigation?
If it's early enough, you could simply create your own bootstrap init method to insert the navigation item, just remember to call $this->bootstrap('navigation') at the top of your method, eg
protected function _initCustomNav()
{
$this->bootstrap('navigation');
$navigation = $this->getResource('navigation');
// add custom item
return $navigation;
}
Disclaimer: I'm pretty sure the navigation resource is just called 'navigation'

Is it possible to directly edit the XML of XIB files?

I tried to do it, but Interface Builder refuses to open the resulting file:
alt text http://img81.imageshack.us/img81/7194/screenshot20091102at252.png
"Interface Builder was unable to determine the type of [file name]"
To answer your question (as you put it in the title): Yes, it is. I did it with TextWrangler for a test (moved a widget) and it works like a charm.
I suspect, you also changed something else (encoding, file name) when you were editing the file. You should try it again with a copy of the xib and do a diff between original and result.
It is possible. Just the task's complexity is approaching the complexity of writing an web app in assembler.
Joking. It's highly not recommended. I think this Xib is not your and Interface builder is just not allowing you to use it.
While the XML format of XIB files is intended to be somewhat human readable, XIB files should never be edited by hand. While the file may appear mergable, the object graph is complex and cannot be maintained except when edited within Interface Builder.
Even if it appears to work, this is unsupported and could lead to more complex problems down the road. It is better to instead file enhancement requests on Interface Builder to provide the capability you need, rather than try to hand edit the XML.

Dynamically include .js files from Zend_Controller_Action?

I came across the case where depending on the execution path I may need to invoke an inclusion of .js file from controller. Is there a nice way of doing it? (besides setting some view variable with actual .js include code)?
See the view helper headScript(). I'm just writing this off the top of my head but I think it works like this:
From within a view file: $this->headScript()->appendFile('filename.js');
From within a controller: $this->view->headScript()->appendFile('filename.js');
And then somewhere in your layout you need to echo out your headScript object:
<?=$this->headScript();?>
Sure, you could do like #Bill Karwin described.
But if you would like to do it really nicely, you need template inheritance - like it is implemented in Django framework for Python for instance. There are some extensions for Zend Framework as well, take a look at Calypso.