Does twig have the equivalent of blades "#push" and or "#stack" - twig

https://laravel.com/docs/9.x/blade#stacks
basically it lets you overwrite block multiple times, but instead of overwriting each other, each call appends to the block.
E.g.
<head>
<!-- Head Contents -->
#stack('myscripts')
</head>
#push('myscripts')
<script src="/example11.js"></script>
#endpush
#push('myscripts')
<script src="/example22.js"></script>
#endpush
results in
<head>
<!-- Head Contents -->
<script src="/example11.js"></script>
<script src="/example22.js"></script>
</head>

Related

how do you create a script to plot multiple lat/lng from a query in cognos report studio using html

i have an working api key --
... just need a little guidance creating a script or loop to grab lat/lng from query and plotting onto a map in html format in cognos report studio
HTML ITEM -> SOURCE TYPE (TEXT)
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<!-- Reference to the Bing Maps SDK -->
<script type='text/javascript'
src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=[YOUR_BING_MAPS_KEY]'
async defer></script>
<script type='text/javascript'>
function GetMap()
{
var map = new Microsoft.Maps.Map('#myMap');
//Add your post map load code here.
}
</script>
</head>
<body>
<div id="myMap" style="position:relative;width:600px;height:400px;"></div>
</body>
</html>
HTML ITEM -> REPORT EXPRESSION
<body onload="GetMap();">
var map = new Microsoft.Maps.Map('#myMap');

How to use preact using html and script tag?

I have a very simple react program that imports react using a script command and a cdn.
How do I covert it to preact while keeping the same structure?
I tried to follow these instruction, but they weren't very clear
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://unpkg.com/react#15/dist/react.js"> </script>
<script src="https://unpkg.com/react-dom#15/dist/react-dom.js"></script>
<script src="https://unpkg.com/babel-standalone#6.15.0/babel.js"></script>
</head>
<style type="text/css">
</style>
<body>
<div id='root'></div>
<script type="text/babel">
function T(props){
return <h1>{props.title}</h1>
}
ReactDOM.render(<T title='welcome'/>,document.getElementById('root'))
</script>
</body>
</html>
As per this github issue you have a couple of different options for using Preact with a script tag. You can directly call h- Preact's version of React.createElement or you can use babel standalone to transform your JSX as you were in your original React example. Here is a Preact conversion of your original example.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/preact/7.2.0/preact.js"></script>
<script src="https://unpkg.com/babel-standalone#6.15.0/babel.js"></script>
</head>
<body>
<div id='root'></div>
<!-- option 1: alias it -->
<script>window.React = { createElement: preact.h }</script>
<script type="text/babel">
function T(props){
return <h1>{props.title}</h1>
}
preact.render(<T title="Welcome" />, document.getElementById('root'));
</script>
</body>
</html>

Linux add new line before and after a matched pattern

I want to put newline before "< script" and after < /script> tags in an HTML file.
sed 's/<script/\'$'\n/g'
I tried that one but it deleted "script" tags.
Sample input:
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JavaScript Ders 2</title> <script type="text/javascript" src="script.js" language="javascript"></script> <script type="text/javascript" src="script.js" language="javascript"></script> <script></script> </head><body> <script type="text/javascript" src="script.js" language="javascript"></script> </body></html>
Sample output:
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JavaScript Ders 2</title>
<script type="text/javascript" src="script.js" language="javascript">
</script>
<script type="text/javascript" src="script.js" language="javascript">
</script>
<script>
</script>
</head><body>
<script type="text/javascript" src="script.js" language="javascript">
</script>
</body></html>
What I have to do?
Thanks
I'm assuming you're just doing this to make it easier to read, rather than attempting to format HTML using sed...
To add newlines before <script and </script (assuming that your version of sed understands \n):
sed -E 's|</?script|\n&|g' file
Match </?script (/? makes the / optional) and replace with a newline, followed by the full match &.
It doesn't quite match the output in your question since it looks like you want to put each opening/closing <script> tag on its own line, rather than just insert lines:
$ sed -E 's|</?script|\n&|g' file
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JavaScript Ders 2</title>
<script type="text/javascript" src="script.js" language="javascript">
</script>
<script type="text/javascript" src="script.js" language="javascript">
</script>
<script>
</script> </head><body>
<script type="text/javascript" src="script.js" language="javascript">
</script> </body></html>
Since you haven't posted any samples so couldn't test it, could you please try following and let me know then.
sed 's/<script>/\n&/;s/<\/script>/&\n/' Input_file
Let's say following is Input_file:
cat Input_file
<script>
fewvfewvvew
</script>
abcd
Then after executing code we will get following output then.
<script>
fewvfewvvew
</script>
abcd

Remove newline before a match - Linux

I want to remove the newline before the </script> in my HTML file with a Linux command (sed, awk...).
Sample input:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript Ders 2</title>
<script type="text/javascript" src="script1.js" language="javascript">
</script>
<script type="text/javascript" src="script2.js" language="javascript">
</script>
<script>
// script kodumuz buraya yazılacak
</script>
</head>
<body>
<script type="text/javascript" src="script3.js" language="javascript">
</script>
</body>
</html>
Sample output:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript Ders 2</title>
<script type="text/javascript" src="script1.js" language="javascript"> </script>
<script type="text/javascript" src="script2.js" language="javascript"> </script>
<script>
// script kodumuz buraya yazılacak</script>
</head>
<body>
<script type="text/javascript" src="script3.js" language="javascript"> </script>
</body>
</html>
I tried different syntax, but none of them could do.
First of all, as mentioned in the comments Don't parse XML with Regex! Never do it, never think about it. Make it a habit not to think about it! Sometimes it might look to be a simple task that can be performed with sed or awk or any other regex parser, but no ...
What you can do, on the other hand—if you really want to use sed or awk — processes the file first with xmlstarlet and convert it into a PYX format.
The PYX format is a line-oriented representation of
XML documents that is derived from the SGML ESIS format.
(see ESIS - ISO 8879 Element Structure Information Set spec,
ISO/IEC JTC1/SC18/WG8 N931 (ESIS))
So what you realy want to do is something like :
$ xmlstarlet pyx <file.html> | do_your_magic_here | xmlstarlet depyx > file.new.html
In your case this would be something like:
$ xmlstarlet pyx file.html \
| awk 'c~/^- *\\n *$/&&/^)script$/{c=$0;next}{print c; c=$0}END{print c}' \
| xmlstarlet depyx
This will output
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"></meta>
<title>JavaScript Ders 2</title>
<script language="javascript" src="script1.js" type="text/javascript"></script>
<script language="javascript" src="script2.js" type="text/javascript"></script>
<script>
// script kodumuz buraya yazılacak
</script>
</head>
<body>
<script language="javascript" src="script3.js" type="text/javascript"></script>
</body>
</html>
This might work for you (GNU sed):
sed 'N;s/\n\(<\/script>\)/\1/;P;D' file
Keep a window of two lines throughout the file and if the second line begins with </script>, remove the preceding newline.

Angular Material doesn't work

I'm starting to use Angular Material and a problem occur: I have this simple page, built with Angular Material, with a NavBar but it doesn't appear, and I don't know why.
This is my page:
<html lang="it">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Angular Material style sheet -->
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.css">
</head>
<body ng-app="MyApp" ng-cloak>
<!-- NavBar -->
<div ng-controller="AppCtrl" ng-cloak="" class="navBardemoBasicUsage" ng-app="MyApp">
<md-content class="md-padding">
<md-nav-bar md-selected-nav-item="currentNavItem" nav-bar-aria-label="navigation links">
<md-nav-item md-nav-click="goto('page1')" name="page1">Page One</md-nav-item>
<md-nav-item md-nav-click="goto('page2')" name="page2">Page Two</md-nav-item>
<md-nav-item md-nav-click="goto('page3')" name="page3">Page Three</md-nav-item>
</md-nav-bar>
<span>{{currentNavItem}}</span>
</md-content>
</div>
<!-- End NavBar -->
<!-- Angular Material requires Angular.js Libraries -->
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-aria.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-messages.min.js"></script>
<!-- Angular Material Library -->
<script src="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.js"></script>
<!-- Your application bootstrap -->
<script type="text/javascript">
(function() {
'use strict';
angular.module('MyApp',['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('AppCtrl', AppCtrl);
function AppCtrl($scope) {
$scope.currentNavItem = 'page1';
}
})();
angular.module('MyApp', ['ngMaterial']);
</script>
</body>
The result is a blank page.
Thanks for help!
There are many things you did wrong in this code. First use ng-app at only in body tag. You also tried to use it in div element so remove that.
You defined MyApp two times in your javascript so remove the last definition.
Remove material.svgAssetsCache import since it is not avaliable. and try to use the below code for in your angular javascript file.
angular.module('MyApp',['ngMaterial', 'ngMessages'])
.controller('AppCtrl', function($scope) {
$scope.currentNavItem = 'page1';
});

Resources