Advertisement
hecrus

Html Block sp example

Nov 30th, 2021
1,262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.10 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[block_blogArticles_get]
  2.     @code nvarchar(128),
  3.     @itemID nvarchar(256),
  4.     @parameters ExtendedDictionaryParameter readonly,  -- langID, username...
  5.     @res nvarchar(max) output
  6. AS
  7. BEGIN
  8.    
  9.     -- извлекаем блок по умолчанию
  10.     declare @s  nvarchar(max) = '', @t nvarchar(max)='', @temp nvarchar(max), @langID int, @par nvarchar(max)
  11.     select @langID = isnull(try_cast(Value as int),1) from @parameters where [key] = 'langID'
  12.     SELECT @temp =   STUFF(
  13.                 (   -- https://placeimg.com/80/80/nature
  14.                     SELECT  '<article class="bla-item card mb-3">
  15.                                 <a href="/blog/'+isnull(t1.code, '')+'">
  16.                                     <img  loading="lazy" class="card-img-top" src="'+isnull([dbo].[rs_resourceLink]('articleTitleImage', t1.id, 0), '')+'" alt="">
  17.                                 </a>
  18.                                 <div class="card-body">                                                            
  19.                                     <div class="bla-title card-title ">
  20.                                         <a class="card-link" href="/blog/'+isnull(t1.code, '')+'"><h5>'+isnull(lang.title, isnull(t1.title,''))+'</h5></a><div class="bl-desc card-text"></div>                                        
  21.                                     </div>
  22.                                 </div>
  23.                             </article>'
  24.                     FROM  (select * from as_articles art
  25.                            where id in (select value from dbo.split(@itemID, ','))) t1
  26.                     left join as_lang_articles lang on lang.articleID = t1.id and lang.langID = @langID
  27.                     order by ord
  28.                        
  29.                     FOR XML PATH(''), TYPE
  30.                ).value('.','nvarchar(max)')
  31.                ,1,0, ''
  32.           )
  33.  
  34.     if( isnull(@temp, '') !='') begin
  35.        set @t = iif(isnull(@langID,0) != 1,'<div class="as-blogArticles">' +
  36.              '<h3>Почитать</h3>' + isnull(@temp, '') +              
  37.              '</div> ','<div class="as-blogArticles">' +
  38.              '<h3>More</h3>' + isnull(@temp, '') +              
  39.              '</div>')
  40.     end
  41.    
  42.    
  43.    
  44.     set @res = @t
  45. END
  46.  
  47. --ru 26.09.2021 12:36:39
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement