view-helpers

How to use the partial in zendframework2

假装没事ソ 提交于 2019-12-06 03:17:30
问题 In ZF1 we use partial in layout.phtml file something like that $this->partial('header.phtml', array('vr' => 'zf2')); How we can do the same in ZF2? 回答1: this can be achieved by echo $this->partial('layout/header', array('vr' => 'zf2')); you can access the variable in view using echo $this->vr; don't forget to add following line in your view_manager of module.config.php file. 'layout/header' => __DIR__ . '/../view/layout/header.phtml', after adding it looks like this return array( 'view

Creating custom helper available in views

不羁岁月 提交于 2019-12-06 02:25:36
问题 I have too much text utility methods, like MakeShortText(string text, int length) , RemoveTags(string text) , TimeAgo(DateTime date) and other. I want to access them from separate helper like in next example: @Text().MakeShortText(Model.Text, 10) Is it possible to create such extension? Or I have to make extension for HtmlHelper like this: @Html.Text().MaksShortText(Model.Text, 10) ? 回答1: You could start by defining a custom TextHelper : public class TextHelper { public TextHelper(ViewContext

TYPO3 ver. 7.6.2 - Condition ViewHelpers evaluated only once

送分小仙女□ 提交于 2019-12-05 17:52:13
Problem: I wrote a conditional VH (extending AbstractConditionViewHelper ) and it works as usually, anyway I realized that in non-cached version it is evaluated only once. Initialy I thought that's my bug, but checked common <f:if> and the problem is identical :S In general when I visit my page for the first time, condition is evaluated and valid result is given, but when I'll refresh the page VH isn't called anymore (checked by setting breakpoint inside the VH) and VH is always treated as FALSE. Only any change in view's code will cause that VH will be evaluated once, and again next refresh

Label is getting displayed below checkbox

£可爱£侵袭症+ 提交于 2019-12-05 16:07:53
<%= f.check_box :openid_enabled %> <%= f.label :openid_enabled, 'OpenID' %> Above code generate this HTML <input type="hidden" value="0" name="application[openid_enabled]"> <input type="checkbox" value="1" name="application[openid_enabled]" id="application_openid_enabled"> <label for="application_openid_enabled">OpenID</label> and the label is getting displayed like [x] OpenID instead of [x] OpenID Do I need to style it or rails helpers have some build in functionality? Added I am using twitter bootstrap CSS framework in my Rails application. I used following to fix the issue without

Erubis block helper throwing error with concat

岁酱吖の 提交于 2019-12-05 08:22:41
I have a couple of block helpers, here's a simple example of what I'm doing: def wrap_foo foo, &block data = capture(&block) content = " <div class=\"foo\" id=\"#{foo}\"> #{data} </div>" concat( content ) end I'm just trying out erubis and it's giving me the following error: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.<< Removing the call to concat removes the error but ends up with my wrapper not being rendered Using: Rails 2.3.5 Erubis 2.6.5 And tried this gem that helps Erubis (though 2.6.4) and Rails

Zend Framework 2 - How to include partial from library

元气小坏坏 提交于 2019-12-04 21:35:47
问题 I wrote a partial which I want to use in several modules. I thought the best way would be to put it into my custom library. But unfortunately I couldn't figure out a way to include this partial without using a very ugly path like: echo $this->partial('/../../../../vendor/myvendor/library/MyVendor/View/Views/FormPartial.phtml' , array(...)); Any ideas how to link to my vendor directory from my view? 回答1: The problem is the resolver can't resolve the path of the view template you had provided.

Rails: Is it possible to write view helpers with HAML syntax?

耗尽温柔 提交于 2019-12-04 16:01:24
问题 During refactoring it would be quite handy just to copy part of HAML template and paste it to helper's code. Currently in such cases 1) I have to rewrite that part of view from scratch 2) I have to use that verbose syntax like content_tag or haml_tag. I know that it's possible to define partials with HAML systax that will serve as helper. Though 1) as for me it's inconvinient to create a separate file for each small tiny function 2) invocation syntax for partial is quite verbose. Ideally i'd

ZF2 - multiple nav menus using the navigation view helper

不打扰是莪最后的温柔 提交于 2019-12-04 11:42:58
I am trying to use a main navigation in combination with a submenu for more specific navigating. In my layout I am calling the view helper like this: $this->navigation('main_navigation')->menu() and in my view I am calling it like this: $this->navigation('sub_navigation')->menu() The problem is that whenever I call the navigation() view helper a more than once , it just outputs the second one in both places. In other words, it's printing the subnav for both the main nav and the subnav menus. My merged config looks like this: 'navigation' => array( 'main' => array( 'home' => array( 'label' =>

Rails :confirm modifier callback?

我是研究僧i 提交于 2019-12-04 10:29:56
问题 I want to call a javascript function that will be conditional upon a user's response to the confirm box. For example, I have the following anchor: <%= link_to 'Sign Out', destroy_session_path, confirm: 'Are you sure that you would like to sign out?', method: :delete %> Should I just abandon the unobtrusive javascript and bind my own jQuery callback to my anchor? Or is there some magical way to pass a callback function to the Rails url helper? I did not see any discussion of callbacks in the

How to use the partial in zendframework2

笑着哭i 提交于 2019-12-04 07:22:48
In ZF1 we use partial in layout.phtml file something like that $this->partial('header.phtml', array('vr' => 'zf2')); How we can do the same in ZF2? this can be achieved by echo $this->partial('layout/header', array('vr' => 'zf2')); you can access the variable in view using echo $this->vr; don't forget to add following line in your view_manager of module.config.php file. 'layout/header' => __DIR__ . '/../view/layout/header.phtml', after adding it looks like this return array( 'view_manager' => array( 'template_path_stack' => array( 'user' => __DIR__ . '/../view' , ), 'display_not_found_reason'