Table of contents
1.
Introduction👨‍✈‍
2.
Built-in helpers✅
2.1.
A📌
2.2.
ASSIGNJS📌
2.3.
B📌
2.4.
BODY📌
2.5.
BR📌
2.6.
CAT📌
2.7.
CENTER📌
2.8.
CODE📌
2.9.
COL and COLGROUP📌
2.10.
DIV📌
2.11.
EM📌
2.12.
FIELDSET📌
2.13.
FORM📌
2.14.
H1, H2, H3, H4, H5, H6📌
2.15.
HEAD📌
2.16.
HTML📌
2.17.
XHTML📌
2.18.
HR📌
2.19.
I📌
2.20.
IFRAME📌
2.21.
IMG📌
2.22.
INPUT📌
2.23.
LABEL📌
2.24.
LEGEND📌
2.25.
LI, OL and UL📌
2.26.
META📌
2.27.
MARKMIN📌
2.28.
OBJECT📌
2.29.
ON📌
2.30.
OPTGROUP📌
2.31.
OPTION📌
2.32.
P📌
2.33.
PRE📌
2.34.
SCRIPT📌
2.35.
SELECT📌
2.36.
SPAN📌
2.37.
STYLE📌
2.38.
TABLE, TBODY, TFOOT, TH, THEAD, TD and TR📌
2.39.
TEXTAREA📌
2.40.
TITLE📌
2.41.
TT📌
2.42.
URL📌
2.43.
embed64📌
2.44.
xmlescape📌
3.
Frequently Asked Questions
3.1.
What is web2py?
3.2.
Why web2py?
3.3.
What is meant by Web application framework?
3.4.
Which is better, web2py or Django?
3.5.
What are HTML tags?
4.
Conclusion
Last Updated: Mar 27, 2024
Medium

Built in Helpers in web2py A to Z

Author Sanchit Kumar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction👨‍✈‍

In web2py, there are HTML helpers, built in helpers, and custom helpers. In this article, we will only learn about built in helpers in web2py. We will see various types of built in helpers in web2py and learn to use them with examples.

Are you ready

built in helpers in web2py a to z

So let us learn about built in helpers in web2py.💫

Built-in helpers✅

A📌

"A" helper is used to build links. Write the following line in view.

{{=A('Click on this link.', _href='http://sitename.domain')}}
link

ASSIGNJS📌

"ASSIGNJS" allows a value on the server side to be used as a client-side js(javascript) value.

For example - if in a controller, you write the following.

return dict(stra='xyz', object=val)

and in a view, you write.

<script>
{{=ASSIGNJS(jsvar=object)}}
…

Then the "jsvar" (javascript variable) will have the value "val" (which is the value passed in the "obj").

B📌

"B" helper makes the contents bold. Write the following line in view.

{{=B('This content is BOLD')}}
bold

BODY📌

The "BODY" helper makes the body of the page. Write the following line in view.

{{=BODY('This helper will make the body of the page.')}}
body

BR📌

The "BR" helper creates a line break. Write the following line in view.

{{=B('There is 1 line break after this line.')}}
{{=BR()*1}}
{{=B('This statement is after line break.')}}
break

CAT📌

"CAT" concatenates other helpers. "CAT" is used in the following statement to concatenate "A" and "B".

{{=CAT('This is ', A('link', _href='http://sitename.domain'), ' and this is ', B('bold'), '.')}}
cat

CENTER📌

"CENTER" helper centres its content. Write the following line in view.

{{=CENTER('This text is in center')}}
center

CODE📌

"CODE" helper performs syntax highlighting for CC++Pythonweb2py code and HTML and is preferable to PRE for code listings. "CODE" can also create links to the web2py API documentation. Write the following line in view.

For example1 - 

{{=CODE('printf("Printing something in C");', language='c')}}
c

For example2 - 

{{=CODE('print "print something in python"', language='python')}}
python

COL and COLGROUP📌

It will be much easier to understand if we discuss COL and COLGROUP from the HTML perspective. The HTML element <col> defines a column within the table. It is generally used within an <colgroup> element. The HTML element <colgroup> defines a group of columns within the table.

Write the following line in view.

{{=COLGROUP('a', 'b', 'c', 'd')}}
{{=COLGROUP('e', 'f')}}
{{=COLGROUP('g', 'h', 'i')}}
{{=COLGROUP('j', 'k', 'l', 'm', 'n')}}
column

DIV📌

"DIV" helper corresponds to HTML element <div>. Write the following line in view.

{{=DIV('This text is in div element')}}
{{=B('This text is outside div element')}}
div

EM📌

"EM" helper emphasises its contents. Write the following line in view.

{{=EM('EM will emphasise this content.')}}
em

FIELDSET📌

The "FIELDSET" helper creates an input field together with its label. Write the following line in view.

{{=FIELDSET('FIELDNAME : ', INPUT(_name='fieldname'))}}
fieldset

FORM📌

"FORM" helper makes a <form>...</form> tag and can process the submitted forms (for example, perform validation of the fields). Write the following line in view.

{{=FORM(INPUT(_type='submit'))}}
form

H1, H2, H3, H4, H5, H6📌

"H1""H2""H3""H4""H5""H6", etc. helpers are used for headings and subheadings. Write the following line in view.

{{=H1('Heading1')}}
{{=H2('Heading2')}}
{{=H3('Heading3')}}
{{=H4('Heading4')}}
{{=H5('Heading5')}}
{{=H5('Heading6')}}
heading

HEAD📌

The "HEAD" helper is used to tag the HEAD of an HTML page. Write the following line in view.

{{=HEAD(TITLE('THIS IS TITLE'))}}
head

HTML📌

The "HTML" built in helper makes the <html> tags; it prepends the tag with a doctype string[xhtml-o,xhtml-w,xhtml-school]. Write the following line in view.

{{=HTML(BODY('something in Body'))}}
html


The HTML helper takes some additional optional arguments having the following default.

HTML(..., lang='en', doctype='transitional')

where doctype can be 'transitional''strict''frameset''html5', or a full doctype string.

XHTML📌

The "XHTML" helper is similar to HTML but creates an XHTML doctype instead, where the doctype can be 'transitional''strict''frameset', or a full doctype string.

HR📌

The "HR" helper creates a horizontal line in an HTML page. Write the following line in view.

{{= HR()}}
hr

I📌

"I" helper makes its contents italics. Write the following line in view.

{{=I('Italic Content')}}
italic

IFRAME📌

The "IFRAME" helper includes another web page(the URL of this page is specified via the "_src" attribute) on the current page. Write the following line in view.

{{=IFRAME(_src='https://www.codingninjas.com/')}}
iframe

IMG📌

"IMG" helper is used to embed images into HTML. Write the following line in view.

{{=IMG(_src='https://files.codingninjas.com/google-12193.png', _alt='google')}}
img

INPUT📌

The "INPUT" helper creates an <input.../> tag. The input tag has an optional attribute _type which can be set to "text" (the default), "checkbox""submit", or "radio". Write the following line in view.

{{=INPUT(_name='name', _value='value')}}
input

LABEL📌

The "LABEL" helper creates a LABEL tag for an INPUT field. When you want to click the text within the <label> element, it toggles the input (this increases the hit area). Write the following line in view.

{{=INPUT(_type='checkbox', _id='0', _value='ninja course')}}
{{=LABEL('Coding Ninjas Course', _for='0')}}
label

LEGEND📌

The "LEGEND" helper creates a legend tag for a field in a form. Write the following line in view.

{{=FIELDSET(LEGEND('This is Legend'))}}
legend

LI, OL and UL📌

"LI" makes a list item, and it should be contained in an "OL" or "UL" tag. Write the following line in view.

{{=P('Ordered List')}}
{{=OL(LI('C'), LI('C++'), LI('Python'))}}
{{=P('Unordered List')}}
{{=UL(LI('C'), LI('C++'), LI('Python'))}}
list


Note ⚠️- OL stands for the ordered list, UL stands for an unordered list, and the list should contain LI tags. If the content is not tagged as LIOL/UL does it automatically.

META📌

"META" is used for building META tags in the HTML head. Write the following line in view.

{{=HEAD(META(_name='priority', _content='urgent'))}}
{{=BODY('Built in Helpers in web2py: A to Z')}}
{{=LI('Meta informations are present in head')}}
meta

MARKMIN📌

"MARKMIN" built in helper uses Markmin wiki syntax. It changes the input text into output HTML using the markmin rules. Write the following line in view.

{{=MARKMIN("This is **bold text** , ''italic'' and this is [[Coding Ninjas. https://www.codingninjas.com/]]")}}
markmin


Here is a basic syntax primer.⚠️

table

OBJECT📌

"OBJECT" embeds objects in the HTML(for example, a flash player). Write the following line in view.

{{=OBJECT('Object built in helper', _src='https://www.codingninjas.com/')}}
object

ON📌

"ON" is for backward compatibility and is simply an alias for "True". It is used exclusively for checkboxes and deprecated as "True" is more Pythonic.

OPTGROUP📌

The "OPTGROUP" helper allows to group together multiple options in a "SELECT". Write the following line in view.

{{=SELECT('OPTION1', OPTGROUP('OPTION2', 'OPTION3'))}}
optgroup

OPTION📌

"OPTION" should only be used as part of an OPTION/SELECT combination. Write the following line in view.

{{=SELECT(OPTION('a'), OPTION('b'))}}
option

P📌

"P" tags a paragraph. Write the following line in view.

{{=P('This is a paragraph')}}
paragraph

PRE📌

"PRE" helper generates a <pre>...</pre> tag for displaying pre-formatted text. Write the following line in view.

{{=PRE('2-SPACES AFTER THIS:', '  ', '2-SPACES BEFORE THIS:')}}
pre

SCRIPT📌

"SCRIPT" helpers include or link a script(for example, JavaScript). The content between this tag will be rendered as an HTML comment. Write the following line in view.

{{=SCRIPT('alert("Coding Ninjas");', _type='text/javascript')}}
script

SELECT📌

"SELECT" makes a <select>...</select> tag. "SELECT" is used with the "OPTION" helper. Those "SELECT" arguments that are not objects of "OPTION" are automatically converted to options. Write the following line in view.

{{=SELECT('Coding', 'Ninjas')}}
select

SPAN📌

The "SPAN" helper is used to tag inline content. Write the following line in view.

{{=SPAN('SPAN', _style='border:2px solid orange')}}
span

STYLE📌

The "STYLE" helper is used to define style information. Here you define how the HTML elements will render inside your browser. Write the following line in view.

{{=STYLE('H1 {color:blue;}')}}
{{=BODY(H1('This is a heading.'))}}
style

TABLE, TBODY, TFOOT, TH, THEAD, TD and TR📌

These tags (along with the optional THEADTBODY and TFOOT helpers) are used to build HTML tables. Write the following line in view.

{{=TABLE(TR(TD('S'), TD('A')), TR(TD('N'), TD('C')))}}
{{=THEAD(TR(TH('THEAD tags table header rows')))}}
{{=BR()}}
{{=TFOOT(TR(TD('TFOOT tags table footer rows')))}}
{{=BR()}}
{{=TBODY(TR('TBODY tags rows contained in the table body'))}}
{{=BR()}}
{{=TR(TD('TR tags a table row'))}}
{{=BR()}}
{{=TH('TH is used instead of TD in table headers.')}}
{{=BR()}}
{{=TD('TD tag defines a standard data cell in the HTML table.')}}
{{=BR()}}
{{=TR('TR tag defines a row in the HTML table.')}}
html tables

TEXTAREA📌

"TEXTAREA" helper makes a <textarea>...</textarea> tag.

{{=TEXTAREA('This is written inside the textarea.')}}
textarea

TITLE📌

"TITLE" tags the title of a page in an HTML header. Write the following line in view.

{{=TITLE('This is Title')}}
title

TT📌

"TT" tags text as monospaced(typewriter) text. Write the following line in view.

{{=TT('monospaced text')}}
monospace

URL📌

The "URL" helper generates internal URL paths for the actions and the static files. Write the following line in view.

{{=URL('path')}}
{{=BR()}}
{{=B("The URL('path') is mapped into - ")}}
{{=B('/[application]/[controller]/path')}}
url

embed64📌

The "embed64" helper encodes the provided (binary) data into base64; it takes the following arguments(optional).

⚡filename: opens and reads this file in 'rb' mode if provided.

⚡file: reads this file if provided.

⚡data: uses the provided data if provided.


🧷embed64(filename=None, file=None, data=None, extension='image/gif')

xmlescape📌

The "xmlescape" built in helper, xmlescape(data, quote=True), returns the escaped string of the provided data. Write the following line in view.

{{=xmlescape('<escape>')}}

xmlescape

Alright! We hope you now understand the built in helpers in web2py.

Frequently Asked Questions

What is web2py?

Web2py is a web application framework that is free and open-source, written in the Python programming language.

Why web2py?

Users can quickly learn server-side web development, which is lightweight and speedy.

What is meant by Web application framework?

A software framework known as a web application framework (WAF) is made to facilitate the creation of web applications, which include web resources, web services, and web APIs.

Which is better, web2py or Django?

The web2py differs from Django due to its smaller size, short learning curve, and lack of project-level configuration files. Compared to PHP and Java, web2py has a significantly more precise syntax, making applications easier to comprehend, maintain, and create.

What are HTML tags?

HTML tags define how web browsers will display and format the content. HTML tags are like keywords.

Conclusion

This article discussed built in helpers in web2py: A to Z. We learnt to use various built in helpers with their code in view and corresponding outputs.

We believe this article on the built in helpers in web2py: A to Z was helpful. To learn more, check out our articles.


Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, System Design, Competitive Programming, JavaScript, etc. Enrol in our courses and refer to the problems available and mock tests. Take a look at the interview bundle and interview experiences for placement preparations.

Happy Learning Ninja! 🥷

Live masterclass