Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3353288
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:07:59+00:00 2026-05-18T02:07:59+00:00

There are two ways to create customs tags with the play framework. By defining

  • 0

There are two ways to create customs tags with the play framework.

  1. By defining a groovy template in app/view/tags
  2. Directly in pure java by having a class extend FastTags

The latest is NOT documented.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:08:00+00:00Added an answer on May 18, 2026 at 2:08 am

    So, similar to how JavaExtensions work by extending the JavaExtensions class, to create a FastTag you need to create a class that extends FastTags. Each method that you want to execute as a tag needs to conform to the following method structure.

    public static void _tagName(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine)
    

    Note the underscore before the name of the tag.

    To understand how to build an actual tag, the easiest way is to look at the source code for a FastTag, and see one in action.

    Here is the source straight from git hub.
    https://github.com/playframework/play/blob/master/framework/src/play/templates/FastTags.java

    Below are a few I have copied, so that I can explain how this works.

    public static void _verbatim(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
        out.println(JavaExtensions.toString(body));
    }
    

    So, this first method is the verbatim tag, and simply calls the toString method on the JavaExtensions, and passes in the body of the tag. The body of the tag would be anything between the open and close tag. So

    <verbatim>My verbatim</verbatim>
    

    The body value would be

    My verbatim
    

    The second example, is slightly more complex. It is a tag that relies on a parent tag to function.

    public static void _option(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
        Object value = args.get("arg");
        Object selectedValue = TagContext.parent("select").data.get("selected");
        boolean selected = selectedValue != null && value != null && selectedValue.equals(value);
        out.print("<option value=\"" + (value == null ? "" : value) + "\" " + (selected ? "selected=\"selected\"" : "") + "" + serialize(args, "selected", "value") + ">");
        out.println(JavaExtensions.toString(body));
        out.print("</option>");
    }
    

    This code works by outputting an HTML option tag, and sets the selected value, by checking which value is selected from the parent tag. The first 3 lines just get data, and set up the data ready to output. Then, the final 3 lines outputs the result of the tag.

    There are many more examples in the source code I have linked to, with varying degrees of complexity, but hopefully this will be a good starting point for you.

    To ensure that your tags do not conflict between projects, or with the core Play tags, you can set up namespaces, using the class level annotation @FastTags.Namespace.

    So, for a hello tag, in a namespace of my.tags, you would do the following

    @FastTags.Namespace("my.tags") 
    public class MyFastTag extends FastTags {
        public static void _hello (Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
            ...
        }
    }
    

    and then in your templates, you would reference the hello tag as

    #{my.tags.hello/}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two different ways to create an empty object in JavaScript: var objectA
I'm trying to create Excel 2007 Documents programmatically. Now, there are two ways I've
I found there are two ways to approach it, ReadDirectoryChangesW and FindFirstChangeNotification . I
In WPF, there are two ways to set the focus to an element. You
POSIX environments provide at least two ways of accessing files. There's the standard system
Is there a difference (performance, overhead) between these two ways of merging data sets?
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There are two popular naming conventions: vc90/win64/debug/foo.dll foo-vc90-win64-debug.dll Please discuss the problems/benefits associated with
There are two scenarios I need to clarify: An executable compiled with .NET 3.5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.