Sharing Layouts (and views)

Hi all,

Is it possible to share layout files among applications? I mean,
having a layout file in a shared folder an make all the applications
read it while maintaining the possibility of having application-
specific layouts.

Something like this:

-- common
   >-- layouts
   > >-- Layout.Common.cfm
-- application1
   >-- layouts
   > >-- Layout.Application1Report.cfm
-- application2
   >-- layouts
   > >-- Layout.Application2Report.cfm

An access to the Layout.Common.cfm from both application1 and 2.

How should I set up the configuration file?

The same thing for views?

Thank you,
Jesus

You could use RenderExternalView()

See docs for example.

Ernst

Hi Jesus,

For sharing/accessing the Layout you do them like this in your event-
handler

setLayout(application2/layout/layout.Application2Report)

Thanks

The problem with using setLayout is that if I later have to change the
path to the shared folder I have to change all references in the
handlers. Ok, I can set a variable at config level, but still...

For the default Layout I can use a relative path (it works), but not
absolute (which would be better) because it concatenates the value to
the application path.

Then I've tried the <Layout> tag

        <Layout file="Layout.Common.cfm" name="CommonLayout">
        </Layout>

but I received the following error:

"Could not find the included template /phonebook/layouts/
CommonLayout.cfm"

Why is it using the name in the path instead of the file attribute?
What am I doing wrong?

Thanks,
Jesus

Jesus,

Unfortunately, the layouts are constricted to their covnentions within an application. We only have as of now a Views External Location setting: http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbConfigGuide#ViewsExternalLocation

Maybe a LayoutsExternalLocation setting can be implemented, where you could have a common shareable external layout location.

Sounds like a good idea, any more opinions, suggestions?

The only caveat with the external layouts location is that it will follow the same pattern as the view external location. The framework will try the conventions location first, if it cannot find it, it will then go to the external location.

Luis

Why not create a simple layout like this? :

#renderExternalView('c:\........\mysharedviews\skins\1\header.cfm')#
#renderView()#
#renderExternalView('c:\........\mysharedviews\skins\1\footer.cfm')#

or
:
#renderExternalView('c:\........\mysharedviews\skins\1\beforeRenderView.cfm')#
#renderView()#
#renderExternalView('c:\........\mysharedviews\skins\1\afterRenderView.cfm')#

Ernst,

I already did something similar to your approach. Just that first I
declared the default layout like this:

<Layouts>
    <!--Declare the default layout, MANDATORY-->
    <DefaultLayout>../../common/ui/layouts/Layout.Common.cfm</

                ...
</Layouts>

I don't like the ../.. thing but at least it works and if needed it's
to be changed only in one place and, what it's more important, only in
the configuration file.

Then I wrote this common layout using renderExternalView to point to
the composing views (just that I use url paths and not filesystem
paths).

        <cfoutput>#renderExternalView('/common/ui/views/UserInfo')#</

Well, this approach is not bad for what I intend to do but, of course,
it would be nicer to have such a way to declare views/layouts
repositories to be search in cascade.

Still what I'd like better is not having to use a relative path
(<DefaultLayout>../../common/ui/layouts/Layout.Common.cfm</

) but just an absolute one (<DefaultLayout>/common/ui/

layouts/Layout.Common.cfm</DefaultLayout>).

Jesus

By the way, any idea on why I get this error:

"Could not find the included template /application1/layouts/
CommonLayout.cfm"

When I try the <Layout> tag like this:

        <Layout file="Layout.Common.cfm" name="CommonLayout">
        </Layout>

?

Thanks,
Jesus

One thing to note Jesus is that layouts and views are meant to be brought in via conventions. So having absolute paths makes no difference, because they always get pre-pended with the “AppMapping” setting.

I think the best approach is to have an externalLayouts Covention that can be used to bring in external layouts.
Any other ideas?

Luis