JNTemplate 模板标签传递url参数
一、模板
private readonly SqlSugar.ISqlSugarClient _db;
public Index1Model(SqlSugar.ISqlSugarClient db)
{
this._db = db;
}
public IActionResult OnGet()
{
string catid = Request.Query["catid"];
var templateContent = "${TemplateValueHelper.PageTitle(catid)}";
var template = Engine.CreateTemplate(templateContent);
template.Set("TemplateValueHelper", new TemplateValueHelper(_db));
template.Set("catid", catid);
var result = template.Render();
return Content(result);
}二、后端
#region 获取当前分类的名字
/// <summary>
/// 获取当前分类的名字
/// </summary>
/// <param name="catid">分类名字</param>
/// <returns></returns>
public string PageTitle(string catid)
{
if (string.IsNullOrEmpty(catid))
{
return "";
}
return CommHelper.GuanLian("article_class", CommHelper.FilterSQL(catid), "dictname");
}
#endregion