diff --git a/extending/template_system/command_new.rst b/extending/template_system/command_new.rst index fe32bf5904f..b9bd40205c9 100644 --- a/extending/template_system/command_new.rst +++ b/extending/template_system/command_new.rst @@ -100,3 +100,38 @@ This is a very simple example for a header only library: def package_id(self): self.info.header_only() + +Custom definitions +------------------ + +Sometimes it's needed to provide additional variables for the custom templates. For instance, if +it's desired to have ``description`` and ``homepage`` to be templated as well: + + + .. code-block:: text + + # Recipe autogenerated with Conan {{ conan_version }} using `conan new --template` command + + from conans import ConanFile + + + class {{package_name}}Conan(ConanFile): + name = "{{ name }}" + version = "{{ version }}" + description = "{{ description }}" + homepage = "{{ homepage }}" + settings = "os", "arch", "compiler", "build_type" + exports_sources = "include/*" + + def package(self): + self.copy("*.hpp", dst="include") + self.copy("LICENSE.txt", dst="licenses") + + def package_id(self): + self.info.header_only() + +now it's easy to overwrite these values from the command line: + + .. code-block:: bash + + $ conan new mypackage/version --template=header_only -d homepage=https://www.example.com -d description="the best package" diff --git a/reference/commands/creator/new.rst b/reference/commands/creator/new.rst index e8ba26bfde4..abddd1f1857 100644 --- a/reference/commands/creator/new.rst +++ b/reference/commands/creator/new.rst @@ -58,6 +58,9 @@ Creates a new package recipe template with a 'conanfile.py' and optionally, excluded -ciu CI_UPLOAD_URL, --ci-upload-url CI_UPLOAD_URL Define URL of the repository to upload + -d DEFINE, --define DEFINE + Define additional variables to be processed within + template **Examples**: @@ -93,5 +96,4 @@ Creates a new package recipe template with a 'conanfile.py' and optionally, $ conan new mypackage/1.0 --template=myconanfile.py # Single template file $ conan new mypackage/1.0 --template=header_only # Template directory - Refer to the section :ref:`template_command_new` for more information about these templates.