Hi,
I''m attempting to call a custom function directly from a template.
I''ve gotten as far as being able to call the function, but it
isn''t
returning the correct value. I''ve created a simple function that just
returns the value passed to it:
echo.rb:
module Puppet::Parser::Functions
newfunction(:echo, :type => :rvalue ) do |args|
args[0]
end
end
When I call this from the template like so:
template.erb
<% Puppet::Parser::Functions.autoloader.loadall %>
Function from template is: <%= scope.function_echo("temp") %>
The returned value is:
Function from template is: 116
For some unknown reason it is returning a number. Does anyone have
any suggestions on how I might get this to work?
Thanks,
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Michael DeHaan
2010-Mar-26 14:59 UTC
Re: [Puppet Users] Calling a function from a template
On Fri, Mar 26, 2010 at 9:54 AM, Mike <mruncieman@gmail.com> wrote:> Hi, > > I''m attempting to call a custom function directly from a template. > I''ve gotten as far as being able to call the function, but it isn''t > returning the correct value. I''ve created a simple function that just > returns the value passed to it: > > echo.rb: > module Puppet::Parser::Functions > newfunction(:echo, :type => :rvalue ) do |args| > args[0] > end > end > > When I call this from the template like so: > > template.erb > <% Puppet::Parser::Functions.autoloader.loadall %> > Function from template is: <%= scope.function_echo("temp") %> > > The returned value is: > > Function from template is: 116 >It looks like our docs/wiki doesn''t have documentation on calling functions from templates. I need to fix that. The ASCII value for ''t'' is 116, which seems to mean an array is not being passed for "args". Does scope.function_echo(["temp"]) work instead? Failing that, I would think you could also assign a variable in the manifest and use that within your template. Let me know what you find out. --Michael -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Mar 26, 10:59 am, Michael DeHaan <mich...@puppetlabs.com> wrote:> Does scope.function_echo(["temp"]) work instead?That did it! Thanks a lot! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael DeHaan
2010-Mar-26 16:57 UTC
Re: [Puppet Users] Re: Calling a function from a template
On Fri, Mar 26, 2010 at 11:08 AM, Mike <mruncieman@gmail.com> wrote:> > > On Mar 26, 10:59 am, Michael DeHaan <mich...@puppetlabs.com> wrote: > > Does scope.function_echo(["temp"]) work instead? > > That did it! Thanks a lot! >Great, I''ll add some info to our docs about this. If anyone else has suggestions on similar tricks/things that are not covered with respect to custom functions, types/providers, etc, let me know! --Michael> > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.