Thymeleaf Custom Labels

Source: Internet
Author: User

/**
* @author Candy
* @since 16/1/13.
*/
@Component
public class Cmsdialect extends Abstractdialect {

@Override
Public String Getprefix () {
return "CRM";
}
@Override
Public set<iprocessor> getprocessors () {
Final set<iprocessor> processors = new hashset<> ();
Processors.add (New Fragmentelementprocessor ());
return processors;
}
}

@Component
public class Fragmentelementprocessor extends Abstractmarkupsubstitutionelementprocessor {


Public Fragmentelementprocessor () {
Super ("Fragment");
}

@Override
Protected list<node> getmarkupsubstitutes (Arguments Arguments, Element Element) {


Final ApplicationContext Appctx = ((Springwebcontext) Arguments.getcontext ()). Getapplicationcontext ();
Final String Path = element.getattributevalue ("path");
Final Fragmentmanager Fragmentmanager =appctx.getbean (fragmentmanager.class);
Final String content = fragmentmanager.findreleasedcontent (path);
Final element container = new Element ("div");
Final text text = new text (content);
Container.addchild (text);

/*
* The abstract Iattrprocessor implementation we are using defines
* That a list of nodes'll be returned, and that these nodes
* would substitute the tag we are processing.
*/
Final list<node> nodes = new arraylist<> ();
Nodes.Add (container);
return nodes;
}

@Override
public int getprecedence () {
return 1000;
}
}

Use of custom labels

<! DOCTYPE html>

<crm:fragment path= "/fragment.php"/>

Website link Address: http://www.thymeleaf.org/doc/tutorials/2.1/extendingthymeleaf.html#attribute-processors

Thymeleaf Custom Labels

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.