Set View Script in Plugin - Check if Exist?

594 views Asked by At

I'm developing a multi-lingual site.

Some languages uses right-to-left layouts and some left-to-right.

So some of my view scripts have another RTL view script that I want to load automatically.

I wrote a plugin that checks if the user is RTL and if yes it adds '.rtl' to the suffix of the file: Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')- >setViewSuffix('rtl.phtml');

the problem is that not all of my view scripts have an rtl view script, so I want to check if the file exist....

the problem with that if I do in my controller $this->render('someScript') then I've got no way to check if the .rtl script exist.. as far as I know.

In short: is there some way (event) to hook up after the action finishes but before it renders?

Maybe I should write a custom view renderer?

Thanks.

1

There are 1 answers

0
Pieter On BEST ANSWER

If the RTL check can only happen after an action has been executed, you could create an action helper, which uses the postDispatch hook to set the viewSuffix via the ViewRenderer and retrieve the path to the view script. Using the view scriptPath and the viewRenderer getViewScript(), you can create the absolute path to the file. It is not a particularly pretty way to accomplish your goals, though.

It might be an idea to create two scriptPaths, one for the LTR and another for the RTL. When the user uses a RTL language, you can add the RTL scriptPath to the view scriptPath stack. That way, Zend_View will first check the RTL directory and use the LTR directory as a fallback.