view-helpers

Razor @helper in App_Code cannot be accessed

孤街醉人 提交于 2019-12-04 04:23:37
In my App_code , I have a helper function called FormatTelephone(string number) in Formatter.cshtml . I tried to access it in a partial view by @Formatter.FormatTelephone(number) . When I test it, it says Compiler Error Message: CS0103: The name 'Formatter' does not exist in the current context What is the likely cause of it? Thanks! I ran into this exact problem when deploying the site onto another server. Make sure the App_Code/Formatter.cshtml file is actually copied to the server! My mistake was the file has a build action that was set to ' None '. Right click on the file and select

Add an 'active' class to all active links in rails?

北城以北 提交于 2019-12-03 12:45:23
问题 Basically, I have a lot of code that looks like this: link_to t('.profile'), business_path(@business), class: '#{'active' if current_page? business_path(@business)}' which isn't very DRY. I was wondering if anyone knows a good way to modify the link_to helper itself to automatically add an 'active' class to all links to the current page. If it helps, I'm open to using HAML or SLIM. 回答1: This is a good case for writing your own helper that wraps the link_to. In your application_helper.rb you

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

跟風遠走 提交于 2019-12-03 10:00:00
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 like my *_helper class to look like this: - def some_helper(*its_args) .some_class = some_ruby

Rails :confirm modifier callback?

不想你离开。 提交于 2019-12-03 05:54:18
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 documentation . By following the link_to source, I see that the :confirm modifier is passed to the

How to call ApplicationController methods from ApplicationHelper

浪尽此生 提交于 2019-12-03 05:23:52
问题 I want to provide csv links in a view and I placed the csv generating code in ApplicationHelper . However I'm getting this error: undefined method `send_data' for #<#<Class:0x0000010151c708>:0x0000010151a070> referencing this: send_data content, :type => "text/plain", :filename => filename, :disposition => 'attachment' If I place the csv code in a controller it works fine. I was hoping to use the helper to avoid having to define routes for every controller I want to provide csv options for (I

Add an 'active' class to all active links in rails?

北城以北 提交于 2019-12-03 02:21:53
Basically, I have a lot of code that looks like this: link_to t('.profile'), business_path(@business), class: '#{'active' if current_page? business_path(@business)}' which isn't very DRY. I was wondering if anyone knows a good way to modify the link_to helper itself to automatically add an 'active' class to all links to the current page. If it helps, I'm open to using HAML or SLIM. This is a good case for writing your own helper that wraps the link_to. In your application_helper.rb you can write a method active_link_to that takes the same params as link_to + current_page, and then just calls

Is there a Fluid viewhelper to truncate an URL? If not, how do I make one?

浪尽此生 提交于 2019-12-02 09:59:05
In TYPO3's Fluid or in Fedext/vhs, is there a viewhelper that can convert http://www.stackoverflow.com/questions/ask into www.stackoverflow.com ? PS: that's the goal: <f:format.raw><f:link.external uri="{item.link}">{item.just-display-the-domain}</f:link.external></f:format.raw> EDIT (adapting the question to the answer I got): If I have to build a custom view helper, how do I proceed? I really doubt if there would be any sensible reason for adding this kind of VH into the core, de facto, writing custom VH is like a piece of cake (when you finally realize it is) so simple formatters can be

../this returns the view object inside inner loop when the parent and child have the same value

不打扰是莪最后的温柔 提交于 2019-12-02 04:19:14
I am just starting with handlebars and I am trying to do a simple double for loop in order to have all the day's time with 15 minute intervals. A very weird thing is happening where if the child and parent have the same values, the view object is being returned instead. This is my code: var handlebarsExpress = require('express-handlebars').create({ helpers: { for: function(from, to, incr, block) { var accum = ''; for(var i = from; i <= to; i += incr) { accum += block.fn(i); } return accum; } } }); app.engine('handlebars', handlebarsExpress.engine); app.set('view engine', 'handlebars'); ... ...

How to use a custom form view helper in Zend Framework 2?

两盒软妹~` 提交于 2019-12-01 08:25:32
I wrote a form view helper, that extends the Zend\Form\View\Helper\FormMultiCheckbox and overwrites its renderOptions(...) method: <?php namespace MyNamespace\Form\View\Helper; use Zend\Form\View\Helper\FormMultiCheckbox as ZendFormMultiCheckbox; class FormMultiCheckbox extends ZendFormMultiCheckbox { protected function renderOptions(...) { ... $label = $escapeHtmlHelper($label); $labelOpen = $labelHelper->openTag($labelAttributes); switch ($labelPosition) { case self::LABEL_PREPEND: $template = $labelOpen . $label . $labelClose . '%s'; break; case self::LABEL_APPEND: default: $template = '%s'

How to use a custom form view helper in Zend Framework 2?

此生再无相见时 提交于 2019-12-01 04:47:10
问题 I wrote a form view helper, that extends the Zend\Form\View\Helper\FormMultiCheckbox and overwrites its renderOptions(...) method: <?php namespace MyNamespace\Form\View\Helper; use Zend\Form\View\Helper\FormMultiCheckbox as ZendFormMultiCheckbox; class FormMultiCheckbox extends ZendFormMultiCheckbox { protected function renderOptions(...) { ... $label = $escapeHtmlHelper($label); $labelOpen = $labelHelper->openTag($labelAttributes); switch ($labelPosition) { case self::LABEL_PREPEND: