Giter Club home page Giter Club logo

Comments (11)

thetutlage avatar thetutlage commented on September 14, 2024

I didn't understand what you mean by {% block classes %}, can you please try to reiterate yourself?

from edge.

imperez avatar imperez commented on September 14, 2024

Sorry for the late response I didn't get the notification for your reply.

Basically I want to be able to use a @section tag in a string as below. This way in a child template I can refer to that block and set whatever value is needed. I was able to do it in Nunjucks in Adonis 3 but I can't seem to do it correctly in edge.

<div class="main-content @section('classes')@endsection"></div>

from edge.

thetutlage avatar thetutlage commented on September 14, 2024

A section is block that contains content. How can A block be used as a class?. What you need is a simple variable

<div class="main-content {{ classes }}"></div>

from edge.

imperez avatar imperez commented on September 14, 2024

from edge.

thetutlage avatar thetutlage commented on September 14, 2024

Not sure what you are trying to achieve, but you can set a local variable and use it as classes

@set('classes', 'foo bar')
<div class="main-content {{ classes }}"></div>

from edge.

imperez avatar imperez commented on September 14, 2024

Yup I saw in another issue that I can use the @set method. Just to give some context on how I was trying to setup my views.

My layout.edge would look like this....

<html>
    <head>
        <title>@section('title')@endsection</title>
    </head>
    <body>
        <div class="main-content @section('classes')@endsection">
            @section('content')
            @endsection
        </div>
    </body>
</html>

Then in my child view I wanted to structure it as so...

@layout('layout')

@section('title')My Wonderful Homepage@endsection
@section('classes')container-fluid@endsection

@section('content)
    <h1>Hello World</h1>
@endsection

Now normally I would use a CMS and store things like title or classes in the database. I just haven't gotten to that point yet. So to keep things clean and not put so much view logic in controllers I wanted to try and set things up as above.

It doesn't seem like edge works that way. It's no big deal since I can update my code to use variables as suggested. I just wanted to give you an example of what I was trying to do.

from edge.

RomainLanz avatar RomainLanz commented on September 14, 2024

Hey @imperez! 👋

What's your issue of using @set and then the following code?

<html>
    <head>
        <title{{ title }}</title>
    </head>
    <body>
        <div class="main-content {{ classes }}">
            @section('content')
            @endsection
        </div>
    </body>
</html>

from edge.

imperez avatar imperez commented on September 14, 2024

The problem is since the classes and title values will change page to page you will have to put in logic in layout.edge to set those variables based on home vs about such as below.

@if(page == 'home')
    @set('title', 'homepage')
    @set('classes', 'container-fluid')
@elseif(page == 'about')
    @set('title', 'about')
    @set('classes', 'container')
@endif

<html>
    <head>
        <title{{ title }}</title>
    </head>
    <body>
        <div class="main-content {{ classes }}">
            @section('content')
            @endsection
        </div>
    </body>
</html>

Now if I were to use @section blocks then it's easier to maintain since I can set up my child views as below. It keeps my layout simple and my child views has the data that applies to it.m.

// home
@layout('layout')

@section('title')My Wonderful Homepage@endsection
@section('classes')container-fluid@endsection

@section('content)
    <h1>Hello World</h1>
@endsection
// about
@layout('layout')

@section('title')About@endsection
@section('classes')container@endsection

@section('content)
    <h1>About</h1>
@endsection

It sounds like this is not the intended use for section blocks. That's fine since I think my use case is very specific.

from edge.

RomainLanz avatar RomainLanz commented on September 14, 2024

I believe you misunderstand how this works.
You can directly set your variables inside your child templates.

// home
@layout('layout')

@section('content)
    @set('title', 'My Wonderful Homepage')
    @set('classes', 'container-fluid')
    <h1>Hello World</h1>
@endsection

from edge.

imperez avatar imperez commented on September 14, 2024

from edge.

thetutlage avatar thetutlage commented on September 14, 2024

Closing since answered

from edge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.