Skip to content

Commit 5d3336c

Browse files
committed
Blog-custom-CSS
1 parent 860c694 commit 5d3336c

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

Block/CustomCss.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magefan\Blog\Block;
10+
11+
use Magefan\Blog\Block\Post\View\Opengraph;
12+
class CustomCss extends Opengraph
13+
{
14+
15+
/**
16+
* Render html output
17+
*
18+
* @return string
19+
*/
20+
protected function _toHtml()
21+
{
22+
$css = $this->config->getCustomCss();
23+
return $css ? ('<style>' . $css . '</style>') : '';
24+
}
25+
}

Model/Config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class Config
112112
const XML_INCLUDE_BLOG_CSS_ALL_PAGES = 'mfblog/developer/css_settings/include_all_pages';
113113
const XML_INCLUDE_BLOG_CSS_HOME_PAGE = 'mfblog/developer/css_settings/include_home_page';
114114
const XML_INCLUDE_BLOG_CSS_PRODUCT_PAGES = 'mfblog/developer/css_settings/include_product_page';
115+
const XML_BLOG_CUSTOM_CSS = 'mfblog/developer/css_settings/custom_css';
115116

116117
/**
117118
* @var ScopeConfigInterface
@@ -288,4 +289,13 @@ public function getPagePaginationType($storeId = null)
288289

289290
return 'page';
290291
}
292+
293+
/**
294+
* @param $storeId
295+
* @return string
296+
*/
297+
public function getCustomCss($storeId = null): string
298+
{
299+
return (string)$this->getConfig(self::XML_BLOG_CUSTOM_CSS, $storeId);
300+
}
291301
}

etc/adminhtml/system.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,9 @@
679679
<field id="include_all_pages">0</field>
680680
</depends>
681681
</field>
682+
<field id="custom_css" translate="label" type="textarea" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
683+
<label>Custom CSS</label>
684+
</field>
682685
</group>
683686
</group>
684687
</section>

view/frontend/layout/blog_css.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@
1313
<css src="Magefan_Blog::css/blog-new.css" />
1414
<css src="Magefan_Blog::css/blog-custom.css" />
1515
</head>
16+
<body>
17+
<referenceContainer name="content">
18+
<block class="Magefan\Blog\Block\CustomCss" name="magefan.blog.custom.css" />
19+
</referenceContainer>
20+
</body>
1621
</page>

0 commit comments

Comments
 (0)