FAQ
Hello All,

I'm trying to a help system to my catalyst app. My idea is to have a
help button. If we are currently at /foo/bar, the help buttons uri
becomes /help/foo/bar. My idea is that the the Help controllers index
will capture everything after /help ( hopefully as an array ). This
data will then be used to look up and display the correct help file (
just a tt template ). So, if the help button is currently pointing to
/help/foor/bar, the system will display the template located at
/help/foo/bar.tt.

Can this be done? Is there a much better way to handle this that I
have not seen or thought of?

Thanks,
Kyle

http://www.kylehall.info
Mill Run Technology Solutions ( http://millruntech.com )
Crawford County Federated Library System ( http://www.ccfls.org )
Meadville Public Library ( http://www.meadvillelibrary.org )

Search Discussions

  • Bill Crawford at Mar 31, 2011 at 4:21 pm
    sub help : Chained('/') Args {
    my ( $self, $c, @path ) = @_;

    my $path = join('/', @path);
    ...
    }
    On 31 March 2011 17:12, Kyle Hall wrote:
    Hello All,

    I'm trying to a help system to my catalyst app. My idea is to have a
    help button. If we are currently at /foo/bar, the help buttons uri
    becomes /help/foo/bar. My idea is that the the Help controllers index
    will capture everything after /help ( hopefully as an array ). This
    data will then be used to look up and display the correct help file (
    just a tt template ). So, if the help button is currently pointing to
    /help/foor/bar, the system will display the template located at
    /help/foo/bar.tt.

    Can this be done? Is there a much better way to handle this that I
    have not seen or thought of?

    Thanks,
    Kyle

    http://www.kylehall.info
    Mill Run Technology Solutions ( http://millruntech.com )
    Crawford County Federated Library System ( http://www.ccfls.org )
    Meadville Public Library ( http://www.meadvillelibrary.org )

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
  • Bill Crawford at Mar 31, 2011 at 4:22 pm

    On 31 March 2011 17:21, Bill Crawford wrote:
    sub help : Chained('/') Args {
    ? ?my ( $self, $c, @path ) = @_;

    ? ?my $path = join('/', @path);
    ? ?...
    }
    Uh, : Chained('/') PathPart('help') Args { ...
  • David Schmidt at Mar 31, 2011 at 4:32 pm

    On Thu, Mar 31, 2011 at 6:22 PM, Bill Crawford wrote:
    On 31 March 2011 17:21, Bill Crawford wrote:
    sub help : Chained('/') Args {
    ? ?my ( $self, $c, @path ) = @_;

    ? ?my $path = join('/', @path);
    ? ?...
    }
    Uh, : Chained('/') PathPart('help') Args { ...

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
    And use

    http://search.cpan.org/~bobtfish/Catalyst-Runtime-5.80032/lib/Catalyst/Request.pm#$req-%3Epath

    for creating the link of the help button
  • Kyle Hall at Mar 31, 2011 at 5:02 pm
    Thanks to Bill and David the info. I'm still learning how to use
    Catalyst, it's almost overwhelming when compared to CakePHP ( which is
    what I started with as my first framework ) here is what I've got:

    My button: <a href="[% c.uri_for('/help', c.action ) %]"
    class="button" id="menu-help">Help</a>

    My Help controller:
    sub index : Chained('/') PathPart('help') Args {
    my ( $self, $c, @path ) = @_;

    my $path = join('/', @path);

    $c->stash->{template} = "help/$path.tt";
    }

    Seems to work fine. Any suggestions for improvements?

    Kyle

    http://www.kylehall.info
    Mill Run Technology Solutions ( http://millruntech.com )
    Crawford County Federated Library System ( http://www.ccfls.org )
    Meadville Public Library ( http://www.meadvillelibrary.org )



    On Thu, Mar 31, 2011 at 12:32 PM, David Schmidt wrote:
    On Thu, Mar 31, 2011 at 6:22 PM, Bill Crawford
    wrote:
    On 31 March 2011 17:21, Bill Crawford wrote:
    sub help : Chained('/') Args {
    ? ?my ( $self, $c, @path ) = @_;

    ? ?my $path = join('/', @path);
    ? ?...
    }
    Uh, : Chained('/') PathPart('help') Args { ...

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
    And use

    http://search.cpan.org/~bobtfish/Catalyst-Runtime-5.80032/lib/Catalyst/Request.pm#$req-%3Epath

    for creating the link of the help button

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
  • Eden Cardim at Apr 11, 2011 at 7:51 pm
    "Kyle" == Kyle Hall writes:
    Kyle> Thanks to Bill and David the info. I'm still learning how to use
    Kyle> Catalyst, it's almost overwhelming when compared to CakePHP ( which is
    Kyle> what I started with as my first framework ) here is what I've got:

    Kyle> My button: <a href="[% c.uri_for('/help', c.action ) %]"
    Kyle> class="button" id="menu-help">Help</a>

    Kyle> My Help controller:
    Kyle> sub index : Chained('/') PathPart('help') Args {
    Kyle> my ( $self, $c, @path ) = @_;

    Kyle> my $path = join('/', @path);

    Kyle> $c->stash->{template} = "help/$path.tt";
    Kyle> }

    Kyle> Seems to work fine. Any suggestions for improvements?

    Is there any non-static content in the help files? If not, you can get
    away with serving the plain files straight from root/help via:

    --8<---------------cut here---------------start------------->8---

    MyApp->config->{'Plugin::Static'}{dirs} = [ 'help' ];

    --8<---------------cut here---------------end--------------->8---

    As usual you'll want to serve that straight via apache or whatever in
    production.

    And in your templates:

    --8<---------------cut here---------------start------------->8---

    <a href="[% c.uri_for('/help', c.req.path) %]"/>Help</a>

    --8<---------------cut here---------------end--------------->8---

    --
    Eden Cardim Need help with your Catalyst or DBIx::Class project?
    Code Monkey http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://blog.edencardim.com/ http://www.shadowcat.co.uk/servers/
  • Octavian Rasnita at Mar 31, 2011 at 5:31 pm
    From: "Kyle Hall" <kyle.m.hall@gmail.com>
    Hello All,

    I'm trying to a help system to my catalyst app. My idea is to have a
    help button. If we are currently at /foo/bar, the help buttons uri
    becomes /help/foo/bar. My idea is that the the Help controllers index
    will capture everything after /help ( hopefully as an array ). This
    data will then be used to look up and display the correct help file (
    just a tt template ). So, if the help button is currently pointing to
    /help/foor/bar, the system will display the template located at
    /help/foo/bar.tt.

    Can this be done? Is there a much better way to handle this that I
    have not seen or thought of?

    Thanks,
    Kyle

    Hi Kyle,

    In the templates where you will display the link to the Help file, you can use:

    <a href="[% c.uri_for_action('/help/index', c.req.path).path %]">Help</a>

    Then in the Help controller's index action you can use:

    sub index :Path :Args(1) {
    my ( $self, $c, $path ) = @_;
    $c->stash( template => "help/$path.tt" );
    }

    And you will need to add the templates with help content under a "help" directory.
    Of course, if you want you can avoid using a centralised "help" directory, and store the templates with help in the directory with the other templates you want to offer help to. In that case, you can use:

    $c->stash( template => "$path-help.tt" );

    ... or something like that.

    It would be pretty simple, but this style is not very reliable nor recommended because there may be more urls for accessing the same content, and in that case you would need to create a template for each one, or there may be necessary to add more than one "Help" link on a page for a certain part of it.

    Unless there is a specific reason you want to keep the help content in static text files, it would be better if you'd keep it in a DB table, and access the wanted help using a label or just a simple ID:

    <a href="[% c.uri_for_action('/help', 'your-label-here').path %]">Help</a>

    It would be much more search engine friendly, and this way you will be able to offer the help in more languages without using Catalyst's I18N for this.

    sub index :Path :Args(1) {
    my ( $self, $c, $id ) = @_;
    my $help = $c->model( 'DB::Help' )->find( $id );
    $c->stash( help => $help );
    }

    Octavian
  • Ronald J Kimball at Mar 31, 2011 at 5:35 pm

    On Thu, Mar 31, 2011 at 1:31 PM, Octavian Rasnita wrote:
    In the templates where you will display the link to the Help file, you can use:

    <a href="[% c.uri_for_action('/help/index', c.req.path).path %]">Help</a>
    What is the purpose of calling .path on the uri returned by
    uri_for_action? Is there some reason the href should be just the
    path, instead of the full URI?

    Ronald
  • Alexander Hartmaier at May 10, 2011 at 12:35 pm
    If you want hostless uris take a look at Catalyst::Plugin::SmartURI.

    Am 2011-03-31 19:35, schrieb Ronald J Kimball:
    On Thu, Mar 31, 2011 at 1:31 PM, Octavian Rasnitawrote:
    In the templates where you will display the link to the Help file, you can use:

    <a href="[% c.uri_for_action('/help/index', c.req.path).path %]">Help</a>
    What is the purpose of calling .path on the uri returned by
    uri_for_action? Is there some reason the href should be just the
    path, instead of the full URI?

    Ronald

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
    *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
    T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
    Handelsgericht Wien, FN 79340b
    *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
    Notice: This e-mail contains information that is confidential and may be privileged.
    If you are not the intended recipient, please notify the sender and then
    delete this e-mail immediately.
    *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMar 31, '11 at 4:12p
activeMay 10, '11 at 12:35p
posts9
users7
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase