Read feature flag from toml in Maud HTML to show/hide div

26 Views Asked by At

I have a feature flag to enable disable feature in rust web application(Using Maud HTML), I want to use the feature flag toggle inside Maud HTML to show/hide div?

In below scenario, div block should enable and display role related contents only if flag is set as administrator or editor respectively.

Implemented below code but is not working as expected irrespective of the flag set in cargo.toml and also no errors as well. Please help here on how to use feature flag check inside a maud HTML appropriately.

EDIT - This is working fine as i made syntax issue in maud by missing braces and also added else condition as div.none which is not required

cargo.toml

[dependencies]
maud = "0.21.0"


[features]
administrator = []
reader=[]
default = ["reader"]

main.rs

use maud::html;
use maud::Markup;

fn main() {
    let htmlcontent = render_html();
    println!("Html content:{}", htmlcontent.into_string())
}

pub fn render_html() -> Markup {
 html! {
    @if cfg!(feature = "administrator")  {
       div.block {
         // TODO: Administrator related UI controls
       }
    } @else if cfg!(feature = "reader") {
       div.block {
         // TODO: Reader related UI controls
      }
    } 
 }
}
0

There are 0 best solutions below