Create a template on AWS (only v3)

@param array $json_array template json array
@param string $name template name (to force it)
@return mixed AwsResult (or Promise for async version)
@throws AwsException if template already exists or wrong syntax
335240
public function createTemplate($json_array, $name="") 
    {
        if ($this->isVersion2())
            throw new \Exception ("Templates are not implemented in version 2");
        $template = $json_array;
        if ($name)
            $template["TemplateName"] = $name;
        return $this->invokeMethod("createTemplate", ["Template" => $template]);
    }
140574
function array_jsonSchema(name) {
  var result = {};
  var itemName;

  itemName = 'itemOf_' + name;

  result.type = 'array';
  if (this.options.required) result.__required = true;

  if (this.schema) {
    result.items = this.schema.jsonSchema(itemName);
  } else {
    result.items = this.caster.jsonSchema(itemName);
  }

  if (result.items.__required) {
    result.minItems = 1;
  }

  __processOptions(result, this.options);
  delete result.items.__required;

  return result;
}
691261
public static function createFromArray($name, array $data = [])
    {
        $type = parent::createFromArray($name, $data);
        \assert($type instanceof self);

        $type->json = $data;

        return $type;
    }
908131
private static function _array(&$data, $name)
	{
		?>
		<li class="krumo-child">

			<div <?php if (count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
				class="krumo-element<?php echo count($data) > 0 ? ' krumo-expand' : '';?>">

					<a class="krumo-name"><?php echo $name;?></a>
					(<em class="krumo-type">Array, <strong class="krumo-array-length"><?php echo
						(count($data)==1)
							? ('1 element')
							: (count($data) . ' elements');
						?></strong></em>)
					<?php

					// callback ?
					//
					if (is_callable($data))
					{
						$_ = array_values($data);
						?>
						<span class="krumo-callback"> |
							(<em class="krumo-type">Callback</em>)
							<strong class="krumo-string"><?php
								echo htmlSpecialChars($_[0]);?>::<?php
								echo htmlSpecialChars($_[1]);?>();</strong></span>
						<?php
					}
				?>
			</div>

			<?php if (count($data))
			{
				self::_vars($data);
			} ?>
		</li>
		<?php
	}
1333489
protected function getTemplate($template, $name)
    {
        $this->template = $this->file->get($template);

        if ($this->needsScaffolding($template))
        {
            return $this->getScaffoldedTemplate($name);
        }

        // Otherwise, just set the file
        // contents to the file name
        return $name . PHP_EOL;
    }
331041
public function generate(string $name, $json): bool
    {
        $this->json = $json;
        $this->name = $this->normalizeName($name);

        if (!$this->canGenerate()) {
            return false;
        }

        $view      = $this->getView();
        $variables = $this->getVariables();

        $path = $this->getPath();
        if (file_exists($path)) {
            unlink($path);
        }
        $this->fileService->render($view, $path, $variables);

        return true;
    }
404183
protected function renderArrayWithCallback($chartOption, $name)
    {
        $result = "";

        if (!empty($chartOption)) {
            // Zend\Json is used in place of json_encode to preserve JS anonymous functions
            $result .= $name . ": " . Json::encode($chartOption[0], false, array('enableJsonExprFinder' => true)) . ", \n";
        }

        return $result;
    }
1207636
public JSONArray optJSONArray(String name) {
		Object object = opt(name);
		return object instanceof JSONArray ? (JSONArray) object : null;
	}
649301
public function format($name, array $data)
    {
        if (!isset($this->_compiled[$name])) {
            throw new RuntimeException("Cannot find template named '$name'.");
        }
        list($template, $placeholders) = $this->_compiled[$name];

        if (isset($data['templateVars'])) {
            $data += $data['templateVars'];
            unset($data['templateVars']);
        }
        $replace = [];
        foreach ($placeholders as $placeholder) {
            $replacement = isset($data[$placeholder]) ? $data[$placeholder] : null;
            if (is_array($replacement)) {
                $replacement = implode('', $replacement);
            }
            $replace[] = $replacement;
        }

        return vsprintf($template, $replace);
    }
545673
public function createTemplate(array $data, $name = 'cookiebar')
    {
        $template = new FrontendTemplate($name);
        $this->setBasicData($template, $data);
        $this->setMoreLinkData($template, $data);
        $this->setAnalyticsCheckboxData($template, $data);

        // Cookie name
        $template->cookie = sprintf('COOKIEBAR_%s', $data['id']);

        return $template;
    }
327360
public function template($name, $data = null)
  {
    $t = $this->getTemplatesEngine()->make($name);

    if ($data) {
      $t->data($data);
    }

    return $t;
  }
287260
public function template($name, array $params = []): ResponseInterface
    {
        if (\is_array($name)) {
            $params = $name;
            $name = null;
        }

        if ($name === null) {
            $handler = $this->app->handler();
            if ($handler instanceof \Closure) {
                throw new \LogicException('Con not build the template from closure handler!');
            }

            $name = \ltrim($handler['app'] . '/' . $handler['controller'] . '/' . $handler['action'], '/');
        } elseif (!\is_string($name)) {
            throw new \InvalidArgumentException('Template name not found!');
        }

        $response = $this->response();

        return $this->app->render($response, $name, $params);
    }
475556
def dump_json(self, pretty=True):
        
        # Build template
        t = {}
        t['AWSTemplateFormatVersion'] = '2010-09-09'        
        if self.description is not None:
            t['Description'] = self.description
        self.elements.dump_to_template_obj(self, t)

        return _CustomJSONEncoder(indent=2 if pretty else None,
                                  sort_keys=False).encode(t)
62428
public static function getJavaBridgeHeader(string $name, array $array): string
    {
        if (array_key_exists($name, $array)) {
            return $array[$name];
        }
        $name = "HTTP_$name";
        if (array_key_exists($name, $array)) {
            return $array[$name];
        }

        return '';
    }
53775
static function createElementNodeFromArray( $name, $array )
    {
        $dom = new DOMDocument( '1.0', 'utf-8' );
        $node = $dom->createElement( $name );
        $dom->appendChild( $node );

        foreach ( $array as $arrayKey => $value )
        {
            if ( is_array( $value ) and
                 count( $valueKeys = array_keys( $value ) ) > 0 )
            {
                if ( is_int( $valueKeys[0] ) )
                {
                    foreach( $value as $child )
                    {
                        unset( $childNode );
                        unset( $importedChildNode );
                        $childNode = eZContentObjectPackageHandler::createElementNodeFromArray( $arrayKey, $child );
                        $importedChildNode = $dom->importNode( $childNode, true );
                        $node->appendChild( $importedChildNode );
                    }
                }
                else
                {
                        unset( $valueNode );
                        unset( $importedValueNode );
                        $valueNode = eZContentObjectPackageHandler::createElementNodeFromArray( $arrayKey, $value );
                        $importedValueNode = $dom->importNode( $valueNode, true );
                        $node->appendChild( $importedValueNode );
                }
            }
            else
            {
                $node->setAttribute( $arrayKey, $value );
            }
        }
        return $node;
    }
380356
def create_template(self):
        """"""
        template = self.template
        # variables = self.get_variables()
        template.add_version('2010-09-09')
        template.add_description('Static Website - Dependencies')

        # Resources
        awslogbucket = template.add_resource(
            s3.Bucket(
                'AWSLogBucket',
                AccessControl=s3.Private,
                VersioningConfiguration=s3.VersioningConfiguration(
                    Status='Enabled'
                )
            )
        )
        template.add_output(Output(
            'AWSLogBucketName',
            Description='Name of bucket storing AWS logs',
            Value=awslogbucket.ref()
        ))

        template.add_resource(
            s3.BucketPolicy(
                'AllowAWSLogWriting',
                Bucket=awslogbucket.ref(),
                PolicyDocument=Policy(
                    Version='2012-10-17',
                    Statement=[
                        Statement(
                            Action=[awacs.s3.PutObject],
                            Effect=Allow,
                            Principal=AWSPrincipal(Join(':',
                                                        ['arn:aws:iam:',
                                                         AccountId,
                                                         'root'])),
                            Resource=[
                                Join('', ['arn:aws:s3:::',
                                          awslogbucket.ref(),
                                          '/*'])
                            ]
                        )
                    ]
                )
            )
        )
        artifacts = template.add_resource(
            s3.Bucket(
                'Artifacts',
                AccessControl=s3.Private,
                LifecycleConfiguration=s3.LifecycleConfiguration(
                    Rules=[
                        s3.LifecycleRule(
                            NoncurrentVersionExpirationInDays=90,
                            Status='Enabled'
                        )
                    ]
                ),
                VersioningConfiguration=s3.VersioningConfiguration(
                    Status='Enabled'
                )
            )
        )
        template.add_output(Output(
            'ArtifactsBucketName',
            Description='Name of bucket storing artifacts',
            Value=artifacts.ref()
        ))
247807
def json_template(data, template_name, template_context):
    
    html = render_to_string(template_name, template_context)
    data = data or {}
    data['html'] = html
    return HttpResponse(json_encode(data), content_type='application/json')