Def in mako

111 views
Skip to first unread message

Никита Игнатченко

unread,
Nov 23, 2014, 2:44:16 AM11/23/14
to mako-d...@googlegroups.com
Hello all! Sorry for my English)

I'm a newbie in mako.
I read the docs, but I can't understand this hook (from edx-platform):

## this needs to be here to prevent the title from mysteriously appearing in the body, in one case
<%def name="pagetitle()" />
 
<%block name="title">
     
<title>
       $
{page_title_breadcrumbs(self.pagetitle())}
     
</title>
  </
%block>


Please, tell me how does this work.

Why fuction closes in some tag?
<%def ... />


Can I write it that way :

<%def name....>
 
<%block>
   
...
 
</%block>
</
%def>

Thx 4 all!

Michael Bayer

unread,
Nov 25, 2014, 11:31:34 AM11/25/14
to mako-d...@googlegroups.com
it depends on the context of how this page is being called (feel free to send a more complete example).     There’s no reason for the named block to be inside a <%def> though, and actually that shouldn’t even be allowed by Mako.


--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mako-discuss...@googlegroups.com.
To post to this group, send email to mako-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/mako-discuss.
For more options, visit https://groups.google.com/d/optout.

Никита Игнатченко

unread,
Nov 25, 2014, 4:51:20 PM11/25/14
to mako-d...@googlegroups.com
Thanks for your help, Michael!
This is a full template (<%def in 45'th line), also this on github:
<!DOCTYPE html>
<!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 8]><html class="ie ie8 lte9 lte8" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 9]><html class="ie ie9 lte9" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if gt IE 9]><!--><html lang="${LANGUAGE_CODE}"><!--<![endif]-->
<%
   
# set doc language direction
   
from django.utils.translation import get_language_bidi
    dir_rtl
= 'rtl' if get_language_bidi() else 'ltr'
%>
<head dir="${dir_rtl}">
   
<meta charset="UTF-8">
   
<meta http-equiv="X-UA-Compatible" content="IE=edge">
    % if responsive:
   
<meta name="viewport" content="width=device-width, initial-scale=1">
    % endif
<%! from django.utils.translation import ugettext as _ %>
<%! from microsite_configuration import microsite %>
<%! from microsite_configuration import page_title_breadcrumbs %>

<%namespace name='static' file='static_content.html'/>
<%! from django.utils.http import urlquote_plus %>

## Define a couple of helper functions to make life easier when
## embedding theme conditionals into templates. All inheriting
## templates have access to these functions, and we can import these
## into non-inheriting templates via the %namespace tag.
<%def name="theme_enabled()">
 
<% return settings.FEATURES.get("USE_CUSTOM_THEME", False) %>
</%def>
<%def name="is_microsite()">
 
<% return microsite.is_request_in_microsite() %>
</%def>

<%def name="stanford_theme_enabled()">
 
<%
   
if not theme_enabled():
     
return False

   
return getattr(settings, "THEME_NAME", None) == "stanford"
  %>
</%def>


## this needs to be here to prevent the title from mysteriously appearing in the body, in one case
<%def name="pagetitle()" />
 
<%block name="title">
     
<title>
       $
{page_title_breadcrumbs(self.pagetitle())}
     
</title>
  </
%block>


 
<script type="text/javascript">
   
/* immediately break out of an iframe if coming from the marketing website */
   
(function(window) {
     
if (window.location !== window.top.location) {
        window
.top.location = window.location;
     
}
   
})(this);
 
</script>

  <script type="text/
javascript" src="/jsi18n/"></script>

  <link rel="
icon" type="image/x-icon" href="${static.url(microsite.get_value('favicon_path', settings.FAVICON_PATH))}" />

  <%static:css group='style-vendor'/>
  <%static:css group='style-app'/>
  <%static:css group='style-app-extend1'/>
  <%static:css group='style-app-extend2'/>

  % if disable_courseware_js:
    <%static:js group='base_vendor'/>
  % else:
    <%static:js group='main_vendor'/>
  % endif

  <%block name="
headextra"/>

<%
  if theme_enabled() and not is_microsite():
    header_extra_file = 'theme-head-extra.html'
    header_file = 'theme-header.html'
    google_analytics_file = 'theme-google-analytics.html'
    footer_file = 'theme-footer.html'

    style_overrides_file = None

  else:
    header_extra_file = None

    if settings.FEATURES['IS_EDX_DOMAIN'] and not is_microsite():
        header_file = microsite.get_template_path('navigation-edx.html')
    else:
        header_file = microsite.get_template_path('navigation.html')

    google_analytics_file = microsite.get_template_path('google_analytics.html')

    if settings.FEATURES['IS_EDX_DOMAIN'] and not is_microsite():
        footer_file = microsite.get_template_path('footer-edx-new.html')

    else:
      footer_file = microsite.get_template_path('footer.html')

    style_overrides_file = microsite.get_value('css_overrides_file')
%>

  % if header_extra_file:
   
<%include file="${header_extra_file}" />
 
% endif

 
<!--[if lt IE 9]>
   
<script src="${static.url('js/html5shiv.js')}"></script>
 
<![endif]-->

 
<%include file="widgets/optimizely.html" />
 
<%include file="widgets/segment-io.html" />

 
<meta name="path_prefix" content="${EDX_ROOT_URL}">
 
<meta name="google-site-verification" content="_mipQ4AtZQDNmbtOkwehQDOgCxUUV2fb_C0b6wbiRHY" />

 
<%include file="${google_analytics_file}" />


% if style_overrides_file:
 
<link rel="stylesheet" type="text/css" href="${static.url(style_overrides_file)}" />
% endif

</head>

<body class="${dir_rtl} <%block name='bodyclass'/
> lang_${LANGUAGE_CODE}">
  <div class="
window-wrap" dir="${dir_rtl}">
    <a class="
nav-skip" href="<%block name="nav_skip">#content</%block>">${_("Skip to this view's content")}</a>

   
<%include file="mathjax_accessible.html" />

 
% if not suppress_toplevel_navigation:
   
<%include file="${header_file}" />
 
%endif

   
<div class="content-wrapper" id="content">
      $
{self.body()}
     
<%block name="bodyextra"/>
   
</div>

  % if not suppress_toplevel_navigation:
    <%include file="${footer_file}" /
>
 
% endif

 
</div>

  <script>window.baseUrl = "${settings.STATIC_URL}";</
script>
 
% if not disable_courseware_js:
   
<%static:js group='application'/>
   
<%static:js group='module-js'/>
 
% endif

 
<%block name="js_extra"/>
</body>
</
html>

<%def name="login_query()">${
  u
"?course_id={0}&enrollment_action={1}".format(
    urlquote_plus
(course_id),
    urlquote_plus
(enrollment_action)
 
) if course_id and enrollment_action else ""
}</%def>


вторник, 25 ноября 2014 г., 21:31:34 UTC+5 пользователь Michael Bayer написал:

Никита Игнатченко

unread,
Nov 25, 2014, 5:00:18 PM11/25/14
to mako-d...@googlegroups.com
This page called from another templates: link to github, because template is very big
Line 11
<%inherit file="../main.html" />

Line 116
<%block name="pagetitle">${get_course_about_section(course, "title")}</%block>



среда, 26 ноября 2014 г., 2:51:20 UTC+5 пользователь Никита Игнатченко написал:
...
Reply all
Reply to author
Forward
0 new messages