Yarko,
Thanks for your well wishes, & response - it sparked an idea.
Define a function x in a controller file y. For example, I defined a
function named 'static' in controller default.py:
def static():
#return a static html page that extends a base layout
if request.args:
response.view = 'static/' + request.args[0] + '.html'
return _EMPTY_DICT #dict()
else: redirect(URL(r = request, f = 'index')) #or however you wish
to handle a missing arg
Decide where the "static" html files will live. For example, I
defined a subdir named 'static' in the standard 'views' dir.
In that subdir create your "static" html files, being sure to extend
the base layout file. For example, privacy_policy.html is:
{{extend 'layout.html'}}
this is the privacy policy
In the html file which is being extended, eg., layout.html, define
links to the "static" html files, naming the function x above, and
proving an argument to identify which "static" file to return:
{{=A(T('Privacy Policy'),_href=URL(r=request,c='default',
f='static', args='privacy_policy'))}}
{{=A(T('Contact Us'),_href=URL(r=request,c='default', f='static',
args='contact'))}}
Now, clicking on one of the links above returns the static html
content in the "static" file within the layout of the base layout
file, as desired. Works well for me. Am sure the code above could be
improved with better error handling, or a layer of misdirection
between argument name and html file name, if desired. One may wish to
use function and subdir names other than 'static', to avoid confusion
with existing controller and directory with those names. If so,
adjust the code above accordingly.
Constructive comments/criticism welcome.
R
On May 23, 1:31 pm, Yarko Tymciurak <[email protected]>
wrote:
> On May 23, 3:16 pm, infodoc <[email protected]> wrote:
>
> > Hello,
>
> > New to web2py. First post.
>
> > What is the best way to serve static html content such as contact
> > info, privacy policy, etc. As I want the content to extend a base
> > html layout, putting it in the static subdir and using the static
> > controller doesn't work since I just get the raw html without the
> > extended layout file. I could set up a function, return a dict with
> > the content, and display wiht an html page of the same name, but that
> > seems overkill to just display some static html.
>
> There are a couple of ways to do what you want: One is to simply
> return the entire static function from
> the static directory, and use the css etc. from that file,
> i.e.http://localhost:8000/myapp/static/myinfo.html
> (this is the way I reference help and documentation files I generate
> as static files, with Sphinx).
>
> You can also use a standard controller function with a redirect to the
> same.
> (search for redirect() inhttp://www.web2py.com/book)
>
> Another way, you hinted at - and perhaps this is what you'll want to
> try first:
> create a controller function, return a dict (no content - basically,
> pass nothing to
> the view; just use the controller name to select the appropriate
> view).
>
> In your view, you can now extend your standard layout, and use
> {{include ...}} to include the static
> content the way that you want within your layout.
>
> I am sure others will chime in with many more suggestions.
>
> Welcome - hope you have lots of fun with web2py!
>
> Regards,
> - Yarko
>
>
>
> > I just want a simple way to return static html in the context of the
> > same layout file I use for dynamic content.
>
> > If this is a repeat question I apologize, & would appreciate a link to
> > the solution.
>
> > Thanks in advance,
>
> > R