Skip to content

Parametrized templates #15

Description

@Jakub21

In SHP v1 it was possible to use a (very rough) workaround to create parametrized templates. Because v2 has no namespaces, it no longer is possible.

Implement a proper system for parametrized templates.

Proposed / example usage:

// define the template
@template[#ExampleTemplate] {
    $div[.Example] {
        $h3 { @slot[#Name] }
        @slot[#Content]
    }
}

// insert twice with different parameters
$div[#Listing] {
    @insert[template = ExampleTemplate] {
        @param[#Name] {Hello}
        @param[#Content] {
            $img[src = "/img/hello.png"]
            Hello world\!
        }
    }
    @insert[template = ExampleTemplate] {
        @param[#Name] {Goodbye}
        @param[#Content] {
            $img[src = "/img/bye.png"]
            The end\!
        }
    }
}

Because SHP functions are executed after the tokens are already parsed into nodes, I doubt it would be possible to parametrize something that is not itself a node (for example, tag parameters).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions