Comments (11)
I didn't understand what you mean by {% block classes %}
, can you please try to reiterate yourself?
from edge.
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.
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.
from edge.
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.
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.
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.
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.
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.
from edge.
Closing since answered
from edge.
Related Issues (20)
- Links are dead in legacy documentation HOT 1
- Simplify prop binding and conditional props HOT 2
- Issue while rendering string having spaces HOT 3
- Condition in one line HOT 2
- Is there a better way to import multiple functions? HOT 4
- Unable to display an image HOT 1
- Is it possible to perform a static analysis of the template Edge.js ? HOT 4
- Just a silly question HOT 2
- Passing values from edge to alpine.js (Question) HOT 3
- Merging props with a default value HOT 1
- SEO HOT 1
- Can not use @ symbol in template files HOT 2
- Blaze/Handlebars vs Edge HOT 1
- <named slot> is not a function HOT 6
- SVG icons not working HOT 5
- Question: What is the difference between partial and component? HOT 2
- `sentenceCase` helper remove accented chars HOT 1
- Creating new feature request does not seem to be possible HOT 2
- Discussion for a new feature - Globally disable html escaping HOT 1
- Discussion for a new feature - @continue and @break tag HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from edge.