Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Dispatch fallback
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Marc Worrell  
View profile  
 More options May 2 2012, 4:11 pm
From: Marc Worrell <m...@worrell.nl>
Date: Wed, 2 May 2012 22:11:38 +0200
Local: Wed, May 2 2012 4:11 pm
Subject: Dispatch fallback

Hi,

TL;DR;

When (in 0.9dev) you add a template like:

        /templates/static/hello.tpl

Then the request:

        http://example.com/hello

will serve that template.
Without adding any dispatch rules.

Long version:

I just added a new notification to the 0.9dev.
It is called #dispatch{} and is used by the site dispatcher to find a matching dispatch rule when no rule matched.

The #dispatch{} observer can return:

        - {ok, integer()} where the integer is a rsc id
        - {ok, #dispatch_match{}}  with a webmachine resource and options filled in
        - {ok, #dispatch_redirect{}} to redirect to a location (must be a fully qualified url!)
        - undefined

With an 'undefined' other modules will be checked and finally a 404 might be served.

In mod_base I added a handler for the #dispatch{} notification:

%% @doc Check if there is a resource or template matching the path.
observe_dispatch(#dispatch{path=Path}, Context) ->
    case m_rsc:page_path_to_id(Path, Context) of
        {ok, Id} ->
            {ok, Id};
        {error, _} ->
            Template = "static/"++Path++".tpl",
            case z_module_indexer:find(template, Template, Context) of
                {ok, _} ->
                    {ok, #dispatch_match{
                        mod=resource_template,
                        mod_opts=[{template, Template}, {ssl, any}],
                        bindings=[{path, Path}, {is_static, true}]
                    }};
                {error, _} ->
                    undefined
            end
    end.

This does two things:

1. Check if there is resource with a set page path, if so return it's id
2. Check if there is a template in a 'static/' directory with the name of the request path.
    If so then this template is served using the resource_template module

- Marc


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dmitrii Dimandt  
View profile  
 More options May 3 2012, 2:17 am
From: Dmitrii Dimandt <dmit...@dmitriid.com>
Date: Thu, 3 May 2012 09:17:24 +0300
Local: Thurs, May 3 2012 2:17 am
Subject: Re: [Zotonic-Dev] Dispatch fallback

One word: AWESOME!

On May 2, 2012, at 23:11 , Marc Worrell wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
M-MZ  
View profile  
 More options May 3 2012, 2:34 am
From: M-MZ <mmzee...@xs4all.nl>
Date: Wed, 2 May 2012 23:34:47 -0700 (PDT)
Local: Thurs, May 3 2012 2:34 am
Subject: Re: Dispatch fallback

Very cool. love it. That also allows other modules to observe dispatch
requests... Endless possibilities.

Maas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »