vapor / leaf-kit

🍃 An expressive, performant, and extensible templating language built for Swift.
https://docs.vapor.codes/4.0/leaf/getting-started
MIT License
47 stars 38 forks source link

Allow `#import` to be empty or not declared #84

Closed Lloople closed 2 years ago

Lloople commented 3 years ago

Is your feature request related to a problem? Please describe. I have a layout.leaf looking like this

<doctype html>
<html>
    <head>
        <link rel="stylesheet" href="mystyles.css"/>
        #import("otherStyles")
    </head
    <body>
        #import("content")
    </body>
</html>

But if I don't export it, I'm having the following error:

"import(\"styles\") should have been resolved BEFORE serialization".

What I have to do now to have it working is adding #export("otherStyles"): #endexport to all of my views, even if they don't have otherStyles.

Describe the solution you'd like I would like that import to be empty, I don't always want to export additional styles, possible solutions are

a) #import("otherStyles") // Modify default behaviour to be optional or allow empty imports
b) #import("otherStyles", allowEmpty: true)
c) #import("otherStyles", "default")

a or c would be perfect 👍