Template Placeholders

Last updated 2 months ago

Let's change the MyFirstPlugin.swift.stencil contents to the following:

import Foundation
class {{ name }} {
init {
<aarkay init{{name}}>
</aarkay>
}
}

Run the command sh scripts/run

You will notice a file modified (denoted by <*> sign and yellow color) and the contents of file will be the following

import Foundation
class AarKay {
init() {
<aarkay initAarKay>
</aarkay>
}
}

Let's modify the actual file generated and change to the following contents

import Foundation
import UIKit
class AarKay {
init() {
<aarkay initAarKay>
print("Initialization")
</aarkay>
}
}
/// AarKayEnd
extension AarKay {}

Now run the sh scripts/run command again

The contents now should be the following

import Foundation
class AarKay {
init() {
<aarkay initAarKay>
print("Initialization")
</aarkay>
}
}

Notice that the line import UIKit is removed but the line print("Initialization") is still preserved. This is because we wrapped it inside the template placeholders - <aarkay (id)> </aarkay> specified inside our templates.

The contents after AarKayEnd line are also preserved because AarKayEnd is a special type of template placeholder after which you can write custom text.